[英]DataGrid.CellStyle applies to whole row in C# WPF App
I am currently working on a small c# wpf project.我目前正在研究一个小型 c# wpf 项目。 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 后执行此操作。
<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.行样式工作正常,但如果例如“Gebucht”为真且 Dringend 也为真,我想将整行显示为绿色,但具有 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.
行样式工作正常,但如果例如“Gebucht”为真且 Dringend 也为真,我想将整行显示为绿色,但具有 Dringend boolean 的单元格除外。
Then you should set the CellStyle
property of the specific column instead of setting the CellStyle
property for the entire DataGrid
, eg:然后您应该设置特定列的
CellStyle
属性,而不是为整个DataGrid
设置CellStyle
属性,例如:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.