I have a base Style
- DataGridRowSelectionStyle
. On some DataGrids
I need to extend this Style
to ink the background
.
DataGridRowSelectionStyle
<Style TargetType="DataGridRow" x:Key="DataGridRowSelectionStyle">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{extensions:Theme Key=DataGrid_Row_IsMouseOver}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{extensions:Theme Key=DataGrid_Row_IsSelected}"/>
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</Style.Triggers>
</Style>
RowStyle
<DataGrid.RowStyle>
<Style TargetType="DataGridRow" BasedOn="{StaticResource DataGridRowSelectionStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding CurrentStatus}" Value="{x:Static production1:ProcessDataEval.OK}">
<Setter Property="Background" Value="{extensions:Theme Key=DGLB_Green}"/>
</DataTrigger>
<DataTrigger Binding="{Binding CurrentStatus}" Value="{x:Static production1:ProcessDataEval.NG}">
<Setter Property="Background" Value="{extensions:Theme Key=DGLB_Red}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Because of the Trigger
order, the two base Triggers
are overwritten and IsMouseOver
or IsSelected
is not triggered anymore.
Solution 1: Extend the RowStyle
. Very bad solution, because I would not need my base Style
anymore..
<DataGrid.RowStyle>
<Style TargetType="DataGridRow" BasedOn="{StaticResource DataGridRowSelectionStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding CurrentStatus}" Value="{x:Static production1:ProcessDataEval.OK}">
<Setter Property="Background" Value="{extensions:Theme Key=DGLB_Green}"/>
</DataTrigger>
<DataTrigger Binding="{Binding CurrentStatus}" Value="{x:Static production1:ProcessDataEval.NG}">
<Setter Property="Background" Value="{extensions:Theme Key=DGLB_Red}"/>
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{extensions:Theme Key=DataGrid_Row_IsMouseOver}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{extensions:Theme Key=DataGrid_Row_IsSelected}"/>
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Solution 2: Create a behavior
and add it to the base Style
which would reorder the final Style
.
Problem: Behavior<TriggerCollection>
or Behavior<Style>
is not working!
The type 'System.Windows.Style' must be convertible to 'System.Windows.DependencyObject' in order to use it as paramter 'T' in the generic class 'System.Windows.Interactivity.Behavior'
Someone got a solution how to use a behavior
in a Style or how to change the trigger order in the inherited Style
?