wpf: add style to ComboBoxItem trough binding
I've a ComboBox
and a Style
for the items. The style is defined by using Style.Triggers
in this way:
<Style>
<Style.Triggers>
<Trigger Property="Tag" Value="false">
<Setter Property="Background" Value="LightBlue"/>
<Setter Property="Foreground" Value="BlueViolet"/>
</Trigger>
<Trigger Property="Tag" Value="true">
<Setter Property="Background" Value="LightGreen"/>
<Sette开发者_Go百科r Property="Foreground" Value="Green"/>
</Trigger>
</Style.Triggers>
</Style>
In order to embed this Style
I would write next :
<ComboBox>
<ComboBoxItem Content="xxxx" Tag="true"/>
<ComboBoxItem Content="yyyy" Tag="false"/>
</ComboBox>
but how I can embed this Style
in case I use DataContext
binding?
Thanks in advance.
You could try adding a style setter to the ComboBox's Resources:
<ComboBox.Resources>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Tag" Value="{Binding SomeValue}" />
</Style>
</ComboBox.Resources>
精彩评论