0
我有一個datagrid綁定到可觀察集合,當我嘗試編輯單元格時,整個行也被編輯了。我已經嘗試了很多東西已經無濟於事。我甚至硬編碼了一個特定的索引,以便只有選中的單元格得到更新。下面的代碼讓我看到確切的單元格,但仍然更新整行。我能做什麼?wpf datagrid在單個單元格中更新全行編輯
<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事件會後,在cellediting上面的代碼給我的只有1項變種X,但整行文字被更新爲優!太。我只想改變確切的當前細胞。謝謝