WP7 - Cancelling ContextMenu click event propagation

Posted by Praetorian on Stack Overflow See other posts from Stack Overflow or by Praetorian
Published on 2011-01-14T23:47:40Z Indexed on 2011/01/15 2:53 UTC
Read the original article Hit count: 211

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.

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.

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.

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?

Thanks for your help!

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about windows-phone-7