我有一个数据网格绑定到一个可观察的集合,当我尝试编辑一个单元格时,整个行也被编辑。我已经尝试了很多东西已经无济于事。我甚至硬编码了一个特定的索引,以便只更新所选的单元格。下面的代码将我带到确切的单元格,但仍然更新整行。我能做什么?
<DataGrid Name="timetableGrid" AutoGenerateColumns="True" SelectionMode="Single" GridLinesVisibility="None"
CellEditEnding="timetableGrid_CellEditEnding" ItemsSource="{Binding Path=TimetableControlDetailsData, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
IsSynchronizedWithCurrentItem="False" SelectionUnit="Cell" CurrentCell="{Binding CellInfo, Mode=OneWayToSource}" >
</DataGrid>
private DataGridCellInfo _cellInfo;
public DataGridCellInfo CellInfo
{
get { return _cellInfo; }
set
{
_cellInfo = value;
OnPropertyChanged("CellInfo");
}
}
private void timetableGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
var test = _vm.CellInfo;
var test1 = test.Item as TimetableControlDetail;
var xs = _vm.TimetableControlDetailsData.Where(c => c.DayID == test1.DayID && c.PeriodID == test1.PeriodID).ToList();
var x = _vm.TimetableControlDetailsData.Where(c => c.DayID == test1.DayID && c.PeriodID == test1.PeriodID ).FirstOrDefault();
x.ClassInstanceDetail.ClassName = "excellent!";
}
经过cellediting活动后,上面的代码只给我一个项目var x,但整个行文本更新为优秀!太。我只想改变当前的确切单元格。感谢
答案 0 :(得分:0)
这不是一个完美的解决方案。但是你为什么不尝试将整个行更新为一个单元格,但它又回来了?