Monday, June 01, 2009

ListView/ListBox Selected Item Color – Active and Out of Focus

The following snippet of XAML can help you set a fixed color scheme for a selected item in the list controls whether the control has focus or not.

   1: <StackPanel Orientation="Vertical">

   2:         <ListView Background="SeaGreen">

   3:           <ListView.Resources>                        

   4:             <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>

   5:             <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}">            

   6:                   Red

   7:             </SolidColorBrush>

   8:             <Style TargetType="{x:Type ListViewItem}">

   9:               <Style.Triggers>

  10:                 <Trigger Property="IsSelected" Value="True">

  11:                   <Setter Property="Foreground" Value="Black"/>

  12:                 </Trigger>

  13:               </Style.Triggers>

  14:             </Style>

  15:           </ListView.Resources>

  16:             <ListViewItem>String 1</ListViewItem>

  17:             <ListViewItem>String 2</ListViewItem>

  18:             <ListViewItem>String 3</ListViewItem>

  19:         </ListView>

  20:         <Button>Button 1</Button>

  21:     </StackPanel>


Anonymous said...

Krishna, thank you very much for responding my question about it on MSDN forum! I really apreciate your help!

Bhargav-------------------------------------------- said...

You are welcome

tomato blog said...

Not something I am looking for but thanks