[英]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.