繁体   English   中英

更改DataGrid(WPF)行中的单元格正在更改下面行中的单元格

[英]Changing a cell in a row of a DataGrid(WPF) is changing cells in rows below

我试图通过使用此代码更改包含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(aprox。)行之后,周期性地在同一列中的单元格中发生背景颜色变化的上述变化。 它仅用于修改单行的Background 有人可以解决这个问题吗? 提前致谢。

试试这个:

<DataGrid Name="SimpleDataGrid" ScrollViewer.CanContentScroll="False" ... />

用于物理单位的滚动。 It DataGrid CanContentScroll默认启用它。

有关更多信息,请参阅MSDN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM