2

データ バインディングを使用して、選択した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>
4

2 に答える 2

0

もう 1 つの回避策は、color プロパティを使用して背景を設定し、HightlightBrushKey を透明に設定することです。

于 2013-08-27T11:00:51.350 に答える