【问题标题】:How to programmatically add a double-click event to a WPF DataGrid Row?如何以编程方式将双击事件添加到 WPF DataGrid Row?
【发布时间】:2014-05-07 22:28:07
【问题描述】:

我可以根据这个问题看到:https://stackoverflow.com/a/3120866/181771 可以将双击事件添加到 DataGrid 行,例如:

<DataGrid ... >
    <DataGrid.ItemContainerStyle>
        <Style TargetType="DataGridRow">
            <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
        </Style>
    </DataGrid.ItemContainerStyle>
    ...
</DataGrid>

我是否可以在 C# 中执行此操作,具体取决于某些条件?如果有,怎么做?

【问题讨论】:

  • 查看 UIElement.AddHadnler()。将处理程序添加到整个网格,然后在事件处理程序中检查 e.OriginalSource。

标签: c# wpf datagrid


【解决方案1】:

试试这个:

myRow.MouseDoubleClick += new RoutedEventHandler(Row_DoubleClick);

【讨论】:

  • 不完全确定,但在行级别添加它可能具有挑战性(性能和编码工作的 int 术语),因为它需要对每个 Db 更改进行后处理 - 我建议处理它在 DataGrid 级别,然后按 OriginalSource 类型对其进行过滤,这不是路由事件的设计目的吗?
猜你喜欢
  • 2014-05-12
  • 1970-01-01
  • 2010-10-16
  • 2015-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-22
  • 1970-01-01
相关资源
最近更新 更多