【问题标题】:Changing a cell in a row of a DataGrid(WPF) is changing cells in rows below更改 DataGrid(WPF) 行中的单元格正在更改下面行中的单元格
【发布时间】: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


    【解决方案1】:

    试试这个:

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

    对于物理单位方面的卷轴。 DataGrid CanContentScroll 默认开启。

    欲了解更多信息,请参阅MSDN

    【讨论】:

      猜你喜欢
      • 2015-11-19
      • 1970-01-01
      • 2011-05-09
      • 2017-08-07
      • 2023-03-28
      • 1970-01-01
      • 2020-04-18
      • 2016-03-29
      • 1970-01-01
      相关资源
      最近更新 更多