【发布时间】:2013-07-20 18:14:30
【问题描述】:
我正在尝试使用以下代码更改包含 WPF DataGrid 中单元格的一些错误数据的 Background:
DataGridRow gridRow = dgInventory.ItemContainerGenerator.ContainerFromIndex(0) as DataGridRow;
DataGridCell cell = dgInventory.Columns[1].GetCellContent(gridRow).Parent as DataGridCell;
cell.Background = Brushes.Gray;
gridRow.IsSelected = true;
gridRow.Focus();
但是,在执行此操作时,当我向下滚动DataGrid 时,每隔 14(大约)行后,同一列中的单元格就会发生上述背景颜色变化。它仅用于修改单行的Background。有人可以解决这个问题吗?提前致谢。
【问题讨论】:
标签: c# wpf datagrid background