I would like to display the odd vs. even selected rows with different background color (gray) in a WPF DataGrid
. I already use the RowBackground="#DDD"
, AlternatingRowBackground="#EEE"
and AlternationCount=2
properties withing DataGrid
itself to alternate the color of non-selected rows.
I've already browsed many threads on StackOverflow, but can't find why the Style.Triggers
has no effect. I use this attached property to determine whether it is an odd or even row.
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<!-- Changes the row style template to have more advanced "borders" (dotted, dashed, etc.) based on value converters -->
<Setter Property="Template">
<!-- ... -->
</Setter>
<!-- Changes the background color of odd rows (will do the same for even one with a slightly different color) -->
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}"
Value="True"/>
<Condition Binding="{Binding (behaviors:DataGridBehavior.IsOddRow), RelativeSource={RelativeSource Self}}"
Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Background"
Value="LightYellow"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<!-- Same principle for even rows -->
<!-- ... -->
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Same (no) effect if I use only one Condition
in the MutliDataTrigger
.
Thanks for any insights :-)