wpf datagrid alternate row coloring wpf datagrid alternate row coloring wpf wpf

wpf datagrid alternate row coloring


Finally, this is what I ended up with for generically setting alternate row colors.

<Style TargetType="{x:Type DataGrid}">    <Setter Property="Background" Value="#FFF" />    <Setter Property="AlternationCount" Value="2" /></Style> <Style TargetType="{x:Type DataGridRow}">    <Style.Triggers>        <Trigger Property="ItemsControl.AlternationIndex" Value="0">            <Setter Property="Background" Value="#CCC"></Setter>        </Trigger>        <Trigger Property="ItemsControl.AlternationIndex" Value="1">            <Setter Property="Background" Value="#EEE"></Setter>        </Trigger>    </Style.Triggers></Style>


Unless already done, you have to set the AlternationCount property of DataGrid:

<DataGrid AlternationCount="2"          ... />

You should additionally check whether the Foreground property is used for any Control in the DataGridRow. Try setting the Background property to test the alternation stuff.


Try setting the alternating background like this:

  AlternationCount="2" AlternatingRowBackground="Bisque"