【问题标题】:Wpf DataGrid DoubleClick has weird behaviourWpf DataGrid DoubleClick 有奇怪的行为
【发布时间】:2011-05-17 16:11:58
【问题描述】:

我正在使用 Wpf DataGrid。我已经处理了 DataGrid 的 MouseDoubleClick 事件以在单独的页面中详细打开记录。所以功能应该就像我双击记录一样,它应该在单独的页面中打开。目前,当我双击 DataGrid 标题(列标题)或 ScrollBar 时,它需要双击所选行(所选记录)。如果只双击行,我希望它双击行。请大家帮忙!!

【问题讨论】:

    标签: c# wpf xaml datagrid double-click


    【解决方案1】:

    尝试在 DataGrid 中处理 LoadingRow 事件,然后在每一行中处理 DoubleClick 事件:

    private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        e.Row.MouseDoubleClick += new MouseButtonEventHandler(Row_MouseDoubleClick);
    }
    

    【讨论】:

      【解决方案2】:

      当使用 DataGrid(单击列标题)时,有时会再次触发 LoadingRow 事件。

      我必须取消订阅并重新订阅 MouseDoubleClick 才能完成这项工作:

      private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e) {
          e.Row.MouseDoubleClick -= Row_MouseDoubleClick;
          e.Row.MouseDoubleClick += Row_MouseDoubleClick;
      }
      

      【讨论】:

        猜你喜欢
        • 2020-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-30
        • 2011-10-10
        • 2013-05-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多