データ バインディングを使用して、選択したListBox アイテムの背景色/ハイライト色を変更したいと考えています。これは私が試してみたものですが、うまくいきません。リソースセクションに「現在のアイテム」コンテキストを持たせる方法がわかりません。
色は、表示されるすべてのアイテムのプロパティです (アイテムごとに異なる値を持ちます)。
<ListBox x:Name="Categorie" ItemsSource="{Binding Categories}" IsSynchronizedWithCurrentItem="True">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{Binding /Color}" />
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{Binding /Color}" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>