I am currently working on a small c# wpf project. I fill my datagrid programmatically and I want to change one cells color in the style without affecting the whole row. I do this after changing the DataGrid Rowstyle.
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Gebucht}" Value="True">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=dringendeBuchung}" Value="True">
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Dringend}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
The rowstyle works fine, but if for example "Gebucht" is true and Dringend is true too I want to display the whole row in green except for the Cell which has the Dringend boolean.
Thank you for your help
The rowstyle works fine, but if for example "Gebucht" is true and Dringend is true too I want to display the whole row in green except for the Cell which has the Dringend boolean.
Then you should set the CellStyle
property of the specific column instead of setting the CellStyle
property for the entire DataGrid
, e.g.:
<DataGrid ... >
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Gebucht}" Value="True">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=dringendeBuchung}" Value="True">
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Dringend}" Header="Dringend">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Dringend}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<!-- + other columns... -->
</DataGrid.Columns>
</DataGrid>