WPF Datagrid 双击 RowDetailsTemplate 也会触发父行上的双击事件

发布于 2024-11-05 21:38:14 字数 293 浏览 0 评论 0原文

我有一个显示数据的 WPF Datagrid。对于 DataGrid 中显示的每个项目,可以展开该项目以显示使用 RowDetailsTemplate 显示的详细数据。 DataGrid Row 和 RowDetailsTemplate 都处理双击事件。

问题是,当双击 RowDetailsTemplate 时,双击事件被正确触发,但父行的双击事件也被触发。这是不受欢迎的行为。

有谁知道如何解决此问题,以便双击 RowDetailTemplate 仅触发 RowDetailsTemplate 双击事件,而不触发其父 Row 双击事件?

I have a WPF Datagrid showing data. For each item displayed in the DataGrid, the item can be expanded to display detail data shown using the RowDetailsTemplate. Both the DataGrid Row and the RowDetailsTemplate handle the Double Click event.

The problem is when double clicking on the RowDetailsTemplate, the double click event is correctly fired, but the double click event for the parent Row is ALSO fired. This is undesired behaviour.

Does anyone know how to resolve this so that double clicking on the RowDetailTemplate only fired the RowDetailsTemplate double click event and not also it's parent Row double click event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人间☆小暴躁 2024-11-12 21:38:14

我遇到过这种情况并观察到两个事件,因此将 e.Handled 设置为 true 没有帮助。

我找不到比保留布尔“锁定”变量更好的解决方案:

private bool lockDoubleClick;

private void dgParent_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (lockDoubleClick) return;
    // parent was double-clicked; do something
}

private void dgChild_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    lockDoubleClick = true;
    // child was double-clicked; do something
    Dispatcher.BeginInvoke(new Action(() => lockDoubleClick = false));
}

I encountered this and observed two events, so setting e.Handled to true did not help.

I couldn't find a better solution than to keep a boolean 'lock' variable:

private bool lockDoubleClick;

private void dgParent_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (lockDoubleClick) return;
    // parent was double-clicked; do something
}

private void dgChild_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    lockDoubleClick = true;
    // child was double-clicked; do something
    Dispatcher.BeginInvoke(new Action(() => lockDoubleClick = false));
}
无人接听 2024-11-12 21:38:14

该事件可能正在冒泡,您可以尝试

e.Handled = true;

在行详细信息中设置双击处理程序以防止父控件进行处理。

The event is probably bubbling, you could try setting

e.Handled = true;

in the row details double click handler to prevent the handling by parent controls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文