加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 05:40:42 所属栏目:百科 来源:网络整理
导读:我试图通过使用此代码更改包含 WPF DataGrid中的单元格的一些错误数据的背景: DataGridRow gridRow = dgInventory.ItemContainerGenerator.ContainerFromIndex(0) as DataGridRow;DataGridCell cell = dgInventory.Columns[1].GetCellContent(gridRow).Pare
我试图通过使用此代码更改包含 WPF DataGrid中的单元格的一些错误数据的背景:
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.)行之后,周期性地在同一列中的单元格中发生背景颜色变化的上述变化.它仅用于修改单行的背景.有人可以解决这个问题吗?提前致谢.

解决方法

试试这个:
<DataGrid Name="SimpleDataGrid" ScrollViewer.CanContentScroll="False" ... />

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

有关更多信息,请参阅MSDN.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读