【发布时间】:2020-10-05 22:46:40
【问题描述】:
我有一个定义自定义主题词典的按钮。
<Button Content="Expand Slot"
FontWeight="SemiBold"
Command="{Binding ElementName=ThisPage, Path=ViewModel.NavigateToSlot, Mode=OneWay}"
CommandParameter="{x:Bind SlotNumber, Mode=OneWay}">
<Button.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<!--Default colors-->
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonForeground" Color="DarkSlateBlue"/>
<SolidColorBrush x:Key="ButtonBorderBrush" Color="DarkSlateBlue"/>
<!--Mouseover colors-->
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="MediumSlateBlue"/>
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="MediumSlateBlue"/>
<!--Colors while being clicked-->
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonForegroundPressed" Color="MediumSlateBlue"/>
<SolidColorBrush x:Key="ButtonBorderBrushPressed" Color="MediumSlateBlue"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Button.Resources>
</Button>
这很好用,但我希望能够跨多个按钮使用同一个字典,而无需编辑每个按钮的 <Button.Resources>
<Button Content="Button 1">
<Button.Resources>
-- Apply my colors --
</Button.Resources>
</Button>
<Button Content="Button 2">
<Button.Resources>
-- Apply my colors --
</Button.Resources>
</Button>
在 UWP 中执行此操作的正确方法是什么?
【问题讨论】:
标签: xaml uwp resourcedictionary