【问题标题】:Add a background image using Styles : Xamarin Forms使用样式添加背景图像:Xamarin Forms
【发布时间】:2017-02-28 12:50:56
【问题描述】:
我想向我的 Xamarin Forms 应用程序添加背景图像。我已经尝试过这里定义的解决方案:Xamarin forms background image for all Pages。但这似乎不起作用。
我也尝试过像这样通过 Xaml 设置它
<Style TargetType="ContentPage">
<Setter Property="BackgroundImage" Value="MyImage.jpg" />
</Style>
无济于事。任何指针将不胜感激。我正在开发 Xamarin Forms 版本 2.3.2.127
【问题讨论】:
标签:
xaml
xamarin
xamarin.forms
【解决方案1】:
您正在为ContentPage 定义一个隐式Style,如果它是在Application 级别ResourceDictionary 定义的,它将应用于所有ContentPages。
由于您提供的上下文和信息稀缺,我只能猜测发生了什么。您的应用中可能没有ContentPages,但有多个页面继承来自ContentPage。如果你想让它工作,你必须在你的Style 中将属性ApplyToDerivedTypes 设置为true:
<Style TargetType="ContentPage" ApplyToDerivedTypes="true">
<Setter Property="BackgroundImage" Value="MyImage.jpg" />
</Style>