【发布时间】:2018-04-14 05:39:37
【问题描述】:
我有这段代码,我想更改数据网格单个单元格的背景。
在我的代码中,更改行的背景。
<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();
我搜索了它和 DataGridView 的代码:
this.dataGridView1.Rows[0].Cells[1].Style.ForeColor = System.Drawing.Color.Red;
但这不适用于 wpf 的 DataGrid。
如何为 DataGrid wpf 更改此代码?
【问题讨论】: