Windows 8 winrt是否可以在资源库中定义笔刷颜色
我正在尝试为页面中的控件定义标准前景色。但是,我发现错误“System.String类型的对象”不能应用于预期类型为“Windows.UI.Xaml.Media.Brush”的属性 在myPage.xaml中Windows 8 winrt是否可以在资源库中定义笔刷颜色,windows-8,styles,windows-runtime,Windows 8,Styles,Windows Runtime,我正在尝试为页面中的控件定义标准前景色。但是,我发现错误“System.String类型的对象”不能应用于预期类型为“Windows.UI.Xaml.Media.Brush”的属性 在myPage.xaml中 <TextBlock TextWrapping="Wrap" Foreground="{StaticResource ForegroundThemeBrush}" /> 在StandardStyles.xaml中 <ResourceDicti
<TextBlock TextWrapping="Wrap"
Foreground="{StaticResource ForegroundThemeBrush}" />
在StandardStyles.xaml中
<ResourceDictionary x:Key="Default">
<x:String x:Key="BackgroundThemeBrush">#484848</x:String>
<x:String x:Key="ForegroundThemeBrush">#efefef</x:String>
</ResourceDictionary>
#484848
#efefef
您应该使用SolidColorBrush而不是x:String作为画笔。您需要定义SolidColorBrush
而不是x:String
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="BackgroundThemeBrush" Color="#484848"/>
<SolidColorBrush x:Key="ForegroundThemeBrush" Color="#efefef"/>
</ResourceDictionary>
虽然这可能在开始时被认为是屈尊于“显然”,但这是真的。很抱歉,我修正了这一点。但这正是引用的错误所说的。可能除了OP可能不知道字符串仅在笔刷属性XML属性上直接指定时才会转换为笔刷之外。