【问题标题】:Fire RowEditEnding event by Pressing Escape Key按 Escape 键触发 RowEditEnding 事件
【发布时间】:2016-05-17 05:39:16
【问题描述】:

当在 WPF Datagrid 中编辑任何单元格时,如果我按 Escape 键,将触发 CellEditEnding 事件。相反,我想触发 RowEditEnding。

我知道当我按 Escape 键一次时,CellEditEnding 事件会触发,而当我第二次按 Escape 键时,RowEditEnding 事件会触发。但我不想要这种行为。我希望当我第一次按 Escape 键时,我想触发 RowEditEnding 事件。

【问题讨论】:

  • CellEditEnding被解雇时,为什么你不解雇RowEditEnding
  • 请显示DataGrid 的XAML 以及绑定到DataGridDataTableObservableCollection)的方式
  • @wajeeh 你能举个例子吗?
  • 类似function onCellEditEnding(args..){ // fire RowEditEnding() },是你的问题吗?
  • @wajeeh 我不知道该怎么做,因为 CellEditEnding 和 RowEditEnding 的事件 args 参数不同。那么,我将什么传递给第二个参数。同样在 RowEditEnding 我使用它的第二个参数,所以我不能传递 null

标签: c# wpf xaml events


【解决方案1】:

从 MSDN 网站查看 DataGridCellEditEndingEventArgsDataGridRowEditEndingEventArgs

因此您可以构建一个新的EventArg 并将其传递给第二种方法。

private void CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) {
    DataGridRowEditEndingEventArgs arg = new DataGridRowEditEndingEventArgs(e.Row, e.EditAction);
    OnRowEditEnding(sender, arg);
}

然后

private void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e) {
    // your code
}

可能有一些错误,因为我现在没有C# IDE。

请注意,您可以添加一些检查以区分方法调用的位置。

【讨论】:

  • 感谢您的回答。我只是很困惑,而你让它变得如此简单。
  • 不客气,如果答案包含拼写错误,请随时编辑。 @Vishal
猜你喜欢
  • 1970-01-01
  • 2012-04-21
  • 2013-09-17
  • 2012-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多