выбранный элемент списка должен выделяться цветом - PullRequest
0 голосов
/ 15 мая 2009

У меня есть ListBox с некоторыми изображениями. Я хочу выделить выделенный элемент некоторым цветом. Я использую WwrapPanel для горизонтального отображения изображений с ScrollViewer. Есть ли способ решить мою проблему?

Ответы [ 2 ]

1 голос
/ 16 мая 2009

Это должно сработать:

<Window x:Class="StackOverflowTests.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" x:Name="window1" Height="300" Width="300">
    <Window.Resources>
        <!-- Specifies the Selection style of ListBoxItems. This changes the forced underlay colors from gray to transparent. -->
        <Style TargetType="ListBoxItem">
            <Style.Resources>
                <!-- This is the color used if the item is selected and the listbox has focus -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
            </Style.Resources>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel Orientation="Vertical">
            <ListBox>
                <ListBoxItem Content="Item 1" />
                <ListBoxItem Content="Item 2" />
                <ListBoxItem Content="Item 3" />
                <ListBoxItem Content="Item 4" />
                <ListBoxItem Content="Item 5" />
                <ListBoxItem Content="Item 6" />
                <ListBoxItem Content="Item 7" />
                <ListBoxItem Content="Item 8" />
                <ListBoxItem Content="Item 9" />
                <ListBoxItem Content="Item 10" />
            </ListBox>
        </StackPanel>       
    </Grid>
</Window>
1 голос
/ 15 мая 2009

Вы должны использовать ItemContainerStyle с триггером для свойства IsSelected, а в триггере вы устанавливаете сеттер для свойства Background

...