Alternate row colors for WPF ListView

To set the alternate background colors for the listview in WPF, set the style and then refer that style object in the listview

  <Style x:Key="ListViewAlternateColors" TargetType="ListViewItem">
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="Gray" />
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="LightGoldenrodYellow" />
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="White" />

and then set the style to the listview

 <ListView Height="170" ItemContainerStyle="{StaticResource ListViewAlternateColors}" Name="listView1" Width="719" AlternationCount="2" SelectionChanged="listView1_SelectionChanged" >
                        <TextBlock Text="{Binding Title}" />    

Hope this helps someone.

Leave a Reply

Your email address will not be published. Required fields are marked *