【发布时间】:2013-02-01 19:48:45
【问题描述】:
我想在我的应用中创建一个solidbrush 资源,它会根据所选主题改变颜色。
有没有办法做到这一点?
【问题讨论】:
标签: .net xaml windows-runtime
我想在我的应用中创建一个solidbrush 资源,它会根据所选主题改变颜色。
有没有办法做到这一点?
【问题讨论】:
标签: .net xaml windows-runtime
好的,我想通了。在 StandardStyles.xaml 中有一个部分
您可以在此处为每个不同的主题添加相同的实心画笔元素。
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
<SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#CEE3F8"></SolidColorBrush>
<SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="#E0E0E0"></SolidColorBrush>
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="#CEE3F8"></SolidColorBrush>
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="#CEE3F8"></SolidColorBrush>
<SolidColorBrush x:Key="HeaderBrush" Color="#FF8AA1B8">
</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="HeaderBrush" Color="#FFCEE3F8">
</SolidColorBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<x:String x:Key="BackButtonGlyph"></x:String>
<x:String x:Key="BackButtonSnappedGlyph"></x:String>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
在这里,我添加了一个“Light”主题,并在其中 2 个主题中添加了一个名为“HeaderBrush”的实心画笔。
要实现这个画笔,只需将它作为资源添加到元素中。就这样……
<AppBar x:Name="BottomAppBar1" Padding="10,0,10,0" BorderBrush="Blue" BorderThickness="0 1 0 0" Background="{ThemeResource HeaderBrush}" AutomationProperties.Name="Bottom App Bar" Opened="BottomAppBar1_Opened" Closed="BottomAppBar1_Closed">
这里我将画笔设置为背景颜色,现在它会随着主题自动改变。
【讨论】: