How do I make my RowStyle
to get applied after AlternatingRowBackground
? I want items, having IsOrange
as true
to have Orange
background regardless of alternating row background, which isn't the case currently.
XAML:
<DataGrid Name="g"
AlternatingRowBackground="Blue"
AlternationCount="2"
...
SelectionMode="Single">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding IsOrange}" Value="Y">
<Setter Property="Background" Value="Orange" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
...
</DataGrid>
It's not a bug. In a
Style
you can't override a local value set for the alternating row. That's why this will not workBut if you set
AlternatingRowBackground
in aStyle
you canThanks to this answer.
In my program I have two classes in addition to main window that contains one DataGird only. Let's start with first class:
MyClass.cs:
I have only two properties,
IsOrange
specifies whether the row should be orange. ((Do not care for the other property.))Now the view model class contains only collection of MyClass.
MyClassViewModel.cs:
In MainWindow.xaml:
finally in MainWindow.xaml.cs:
and this is the result:
you can send me your email to send you the app.
Good Luck :)