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
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.
Of course, you're right! However, I did manage to achieve this by creating a class that derives from XamContextMenu, and then override the OnOpening method. I can then call the static method.
Thanks, Stefan