【问题标题】:WPF XAML DataGrid : How to add PreviewKeyUp event to all cells?WPF XAML DataGrid:如何将 PreviewKeyUp 事件添加到所有单元格?
【发布时间】:2011-06-25 03:54:36
【问题描述】:

如何将 PreviewKeyUp 事件添加到所有单元格?

我想在编辑模式下捕捉每个单元格的 Tab 键按下情况。

谢谢大家

【问题讨论】:

    标签: wpf events xaml datagrid cell


    【解决方案1】:

    只需在 DataGrid 本身或窗口等父元素之一中注册PreviewKeyUp,Datagrid 就在其中。然后分析事件 OriginalSource 以了解事件的来源。

    要访问行数据,您可以执行以下操作:

    FrameworkElement fe=e.OriginalSource;
    if(null != fe){
       YourRowDataObject rowData=fe.DataContext as YourRowDataObject;
       // work here with your data
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多