WP7 - 取消ContextMenu单击事件传播 [英] WP7 - Cancelling ContextMenu click event propagation

查看:127
本文介绍了WP7 - 取消ContextMenu单击事件传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Silverlight工具包的 ContextMenu UIElement 之间被点击时,我遇到问题,注册了一个Tap事件 GestureListener 。上下文菜单单击传播到底层元素,并触发其点击事件。

I'm having a problem when the Silverlight toolkit's ContextMenu is clicked while it is over a UIElement that has registered a Tap event GestureListener. The context menu click propagates to the underlying element and fires its tap event.

例如,说我有一个 ListBox 和每个 ListBoxItem 其中注册了一个 ContextMenu 和一个Tap GestureListener 。假设单击上下文菜单项2应该会带你到Page1.xaml,而点击任何ListBox项目本身应该带你到Page2.xaml。

For instance, say I have a ListBox and each ListBoxItem within it has registered both a ContextMenu and a Tap GestureListener. Assume that clicking context menu item2 is supposed to take you to Page1.xaml, while tapping on any of ListBox items themselves is supposed to take you to Page2.xaml.

如果我打开ListBox中item1的上下文菜单,然后上下文菜单项2位于ListBox item2的顶部。当我点击上下文菜单项2时,我感到怪异的行为,应用程序导航到Page1.xaml,然后立即到Page2.xaml,因为点击事件也触发了点击手势 ListBox item2。

If I open the context menu on item1 in the ListBox, then context menu item2 is on top of ListBox item2. When I click on context menu item2 I get weird behavior where the app navigates to Page1.xaml and then immediately to Page2.xaml because the click event also triggered the Tap gesture for ListBox item2.

我已经在调试器中验证了它始终是接收点击事件的上下文菜单。如何取消上下文菜单项点击的路由事件传播,因此它不会到达ListBox item2?

I've verified in the debugger that it is always the context menu that receives the click event first. How do I cancel the context menu item click's routed event propagation so it doesn't reach ListBox item2?

感谢您的帮助!

推荐答案

您可以通过执行以下操作来解决问题:

You can get around the problem by doing the following:


  • 在上下文菜单的已打开处理程序集 LayoutRoot.IsHitTestVisible LayoutRoot 是根 UIElement )到 false

  • In the context menu's Opened handler set LayoutRoot.IsHitTestVisible (LayoutRoot is the default name for the root UIElement) to false

在上下文菜单的 Closed 处理程序集 LayoutRoot.IsHitTestVisible 返回到 true

In the context menu's Closed handler set LayoutRoot.IsHitTestVisible back to true

这篇关于WP7 - 取消ContextMenu单击事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆