根据单元格的内容设置 DataGridRow 的背景 [英] Set the Background of a DataGridRow based on the content of a cell
本文介绍了根据单元格的内容设置 DataGridRow 的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用 XAML 根据行的一个单元格的内容动态设置行的背景?
Is there a way, using XAML, to dynamically set the background of a row based on the content of one of it's cells?
谢谢,
菲尔
推荐答案
您可以为行定义样式并使用 DataTrigger 更改颜色.像这样:
You can define a style for a row and change the color using DataTrigger. Something like this:
<DataGrid>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding BooleanPropertyOnObjectBoundToRow}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
此处BooleanPropertyOnObjectBoundToRow
是单元格绑定到的数据对象上的布尔属性.
Here BooleanPropertyOnObjectBoundToRow
is a boolean property on your data object one the cells is bound to.
这篇关于根据单元格的内容设置 DataGridRow 的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文