【问题标题】:How to set a Background image in UNO UWP?如何在 UNO UWP 中设置背景图像?
【发布时间】:2018-07-07 17:18:37
【问题描述】:

我正在尝试放置背景图片,到目前为止我有这个代码:

<Grid.Background>
    <ImageBrush ImageSource="ms-appx:///Assets/Windows-10-Hero-Ninja-Cat-1024x576-03a71eed2a427425.jpg" Stretch="UniformToFill"/>
</Grid.Background>

在 Windows 10 上的 UWP 上以这种方式显示:

但是当我构建 WASM 或 Android 时,背景图像没有出现。

设置文件属性构建操作:内容,复制到输出目录:不要复制。

【问题讨论】:

  • 现在应该可以在更新的 Uno 版本中使用。

标签: xaml uno-platform


【解决方案1】:

Uno 的 WASM 目标仍处于试验阶段,某些功能尚不可用。唯一尚未实现的背景画笔SolidColorBrush

它适用于 iOS (source code here),但不适用于 Android。

由于您已经在&lt;Grid&gt; 中,您可以简单地将您的图片作为第一个元素:

  <Grid>
    <Image Source="ms-appx:///Assets/Windows-10-Hero-Ninja-Cat-1024x576-03a71eed2a427425.jpg" Stretch="UniformToFill" />
    [... put your other controls here]
  </Grid>

【讨论】:

  • 我敢打赌你可以帮我here
【解决方案2】:

如果您需要为每个平台使用不同的后台方法,请使用 xaml 条件前缀。

https://platform.uno/docs/articles/platform-specific-xaml.html#xaml-conditional-prefixes

你可以使用

最终,您可以通过灵活的标记获得相同的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-06
    • 2018-01-08
    • 1970-01-01
    • 2022-10-07
    • 1970-01-01
    • 2019-07-24
    • 2014-11-06
    • 2020-08-17
    相关资源
    最近更新 更多