Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1590
Add handler for XamContextMenu.ContextMenuOpeningEvent
posted

Hi,

I'm trying to create a single static method that will react to any ContextMenuOpeningEvent, raised by any XamContextMenu. I tried to subscribe like this:

EventManager.RegisterClassHandler(typeof(XamContextMenu), XamContextMenu.ContextMenuOpeningEvent, new RoutedEventHandler(OnContextMenuOpening), true); 

But for some reason the code never reaches my OnContextMenuOpening method. When I try to do the same for e.g. Button.ClickEvent this line works. How can I do this?

Regards, Stefan

Parents
No Data
Reply
  • 54937
    Verified Answer
    Offline posted

    I think you're looking at the FrameworkElement.ContextMenuOpeningEvent (e.g. if you right click on the ContextMenuOpeningEvent and go to the definition) which is a routed event that the framework raises on an element as it traverses up the visual tree searching for the context menu to be displayed when right clicking or using the keyboard to show a context menu (e.g. shift+f10). The Opening event of the xamContextMenu isn't a routed event so currently there is no way to create a static handler for that event for all instances of that element type.

Children