リスト ボックス内の項目の背景色を動的に設定するにはどうすればよいですか? つまり、ビジネス オブジェクトにもバインドしているプロパティがあるため、いくつかのビジネス ルールに基づいて、背景色を変更したいですか?
<ListBox Background="Red">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Red"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Margin="5">
<TextBlock VerticalAlignment="Bottom"
FontFamily="Comic Sans MS"
FontSize="12"
Width="70"
Text="{Binding Name}" />
<TextBlock VerticalAlignment="Bottom"
FontFamily="Comic Sans MS"
FontSize="12"
Width="70"
Text="{Binding Age}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
編集:ここに書かれています
Silverlight では、カスタム スタイルに x:Key 属性を追加し、それらを静的リソースとして参照する必要があります。Silverlight は、TargetType 属性値を使用して適用される暗黙的なスタイルをサポートしていません。
これは私のアプローチに影響を与えますか?