绑定Classes
<ListBox Items="{Binding MyItems}">
<ListBox.Styles>
<Style Selector="TextBlock.myClass">
<Setter Property="Background" Value="Red" />
</Style>
<Style Selector="TextBlock.myClass2">
<Setter Property="Background" Value="Green" />
</Style>
</ListBox.Styles>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock
Classes.myClass="{Binding MyProperty}"
Classes.myClass2="{Binding !MyProperty}"
Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>最后更新于