在 celledit 结束时,我只想在值更改时触发方法
我有某些可编辑列,我想仅在值已更改时才触发该方法
DataGridCellEditEndedEventArgs 属性e.EditAction
始终返回提交
最佳答案
您可以收听DataGrid.PreparingCellForEdit事件(或者可能 DataGrid.BeginningEdit 但我不是 100% 肯定)并存储该点单元格的值。
然后,不要监听 DataGrid.CellEditEnded
,而是监听 DataGrid.CellEditEnding 。此事件专门设计用于为您提供取消编辑的选项,因此它不会被视为提交。 DataGridCellEditEndingEventArgs因为它提供了 Cancel bool
属性。检查新值是否与旧值相同,如果相同,请将 Cancel
属性设置为 true
。然后,当 CellEditEnded
事件触发时,其 EditAction
将为 Cancel
。
void MyGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs args)
{
//store current value
}
void MyGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs args)
{
//check if values are the same
if (valuesAreSame)
args.Cancel = true;
}
关于c# - silverlight 数据网格单元编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16883701/