【发布时间】:2016-10-06 15:00:23
【问题描述】:
我目前正在开发一个Xamarin.Forms 应用程序,并且正在专门应用样式。我已经看到了放置在所需平台项目的App.xaml 文件中的全局样式示例,并认为您可以使用DynamicResourcereference 引用全局声明的样式,如下所示:
在 UWP 中App.xaml
<Application
<Application.Resources>
<ResourceDictionary>
<Style x:Key="myLabel" TargetType="TextBlock">
<Setter Property="Foreground" Value="Purple" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
然后在便携式项目中的Login.xaml
<Label Text="hey hey im purple" Style="{DynamicResource myLabel}" />
我的印象是这段文字应该是紫色的,但事实并非如此。我可以使用在使用它的页面中定义的ResourceDictionary 来设置Label 的样式,但是我不能在全局中使用它。
有趣的是,如果我声明一个隐式全局样式,它就可以工作:
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Purple" />
</Style>
当我使用 x:Key="myVariable" 尝试显式全局样式时,它不起作用。
tldr;全局显式样式对我不起作用(但全局隐式样式正在起作用)
任何想法堆栈社区?谢谢!
【问题讨论】:
标签: xamarin styles win-universal-app uwp-xaml