I have a datagrid that I'm trying to make resemble:
I'm using the AlternatingRowBackground
attribute to perform the alternating colors. For the fixed color section, I have XAML that resembles:
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ShouldBeFixedColor}" Value="True">
<DataTrigger.Setters>
<Setter Property="Background" Value="Blue" />
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
The problem with this approach is that the "alternating color" takes precedence over the fixed color style trigger. So, at the bottom instead of blue-blue-blue it is blue-gray-blue.
Any ideas on how to archive the desired coloring? I'd rather do this all at the XAML level if possible.
Thanks!
Made some changes based upon other SO answers. Hopefully this helps someone in the future.
AlternatingRowBackground=...
from the grid. Add AlternationCount="2"
Add the block below to do the styling (manually doing the alternating rows)
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="AlternationIndex" Value="0">
<Setter Property="Background" Value="White" />
</Trigger>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="WhiteSmoke" />
</Trigger>
<DataTrigger Binding="{Binding Path=Selectable}" Value="False">
<DataTrigger.Setters>
<Setter Property="Background" Value="LightGray" />
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With