在ResourceDictionary
文件中我有一个样式,我尝试为该样式添加一些资源。遗憾的是,成员Resources
无法识别或无法访问。我需要在样式中明确地保留资源。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestProject.Resources">
<Style>
<Style.Resources> <!--Style doesn't like it here-->
Uwp的风格似乎并不喜欢它。是否有任何等效或充分的解决方法?或者我做错了。
答案 0 :(得分:1)
Style
没有Resources
属性(请参阅documentation)。控件和视觉元素都可以。如果要添加资源,可以在控件下添加它们,所有这些都与Style
元素处于同一级别:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestProject.Resources">
<SolidColorBrush x:Key="MyBrush" ... />
<Style>
<!-- use MyBrush in this style -->
如果您在与Style
相同的级别上定义资源,那么它们将在全局范围内可用,但这与默认的XAML资源字典(generic.xaml
)中定义默认UWP样式的方式类似。