[英]how to set background for specific cells of DataGrid wpf?
我有一个DataTable,我想更改其“位置”字段为true的特定单元格的背景。
我用C#代码设置了DataGrid的ItemSource。
我尝试此代码,但不起作用:
<DataGrid x:Name="dg">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Place}"
Value="True">
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
在C#代码中:
DataTable dt = new DataTable();
dt.Columns.Add("Time", typeof(string));
dt.Columns.Add("Place", typeof(string));
dt.Rows.Add( "23:00", "true");
dt.Rows.Add( "21:00", "true");
dt.Rows.Add( "19:00", "false");
dg.ItemsSource = dt.AsDataView();
如何将DataTrigger与我提交的DataTable的“位置”绑定?
此问题的答案在以下注释中:
字符串,因为值区分大小写
字段中的字符串必须与tag值中的字符串相等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.