tags:

views:

184

answers:

2

I have a listbox with some images.I want to hightlight the selected item with some color. Iam using wrap panel to display images horizontally with scrollviewer. Is there any way to solve my problem.

A: 

You should use a ItemContainerStyle with a trigger on the IsSelected property, and in the Trigger you put a setter on the Background property

Thomas Levesque
I dont about triggers. can u plz post the code of that.
Thanks for the reply. I got the solution with ur help.
Don't forget to mark the answer as accepted ;)
Thomas Levesque
A: 

This should do the trick:

<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>
Carlo