我有ListBoxItem
样式,我使用普通前景和资源" GrayBrush2"突出显示。
选择后,可以通过样式的触发器和设置器将前景属性更改为白色。但我也想在选择项目时将GrayBrush资源本地覆盖为黑色。
示例代码:
<Style TargetType="ListBoxItem"
BasedOn="{StaticResource MetroListBoxItem}">
<!-- This will override the GrayBrush2 Resource with my local Value.
I want tos to be only applies when my Item is selected. -->
<Style.Resources>
<SolidColorBrush x:Key="GrayBrush2"
Color="{StaticResource HighlightColor}" />
</Style.Resources>
<Style.Setters>
<Setter Property="Foreground"
Value="{DynamicResource BlackBrush}" />
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Foreground"
Value="{DynamicResource WhiteBrush}" />
<!-- Here I want to apply the resources Part dynamically -->
</Trigger>
</Style.Triggers>
</Style>