Occurs when any context menu on the element is opened.
Assembly: PresentationFramework (in PresentationFramework.dll)
To manually open context menus, handlers of the events should mark the relevant event as handled. Otherwise, the existing value of the ContextMenu property will be used to automatically open a context menu. Marking the event handled will effectively cancel the default action, and could be an opportunity to reset the value of the ContextMenu property and then open the new ContextMenu. However, there is a timing issue you should be aware of. In order to completely replace the context menu through a handler, the initial context menu must not be null / empty. Alternatively, you might need to handle the event and then manually open a new context menu. For details, see How to: Handle the ContextMenuOpening Event.
To use this event as an EventTrigger in a style, you must reference the underlying attached event:
<EventTrigger RoutedEvent="ContextMenuService.ContextMenuOpening"> <!-- storyboard here ... --> </EventTrigger>
(This usage is required because the event implementation on FrameworkElement that exposes the underlying service event does not map the identifier such that you can use it in triggers).
ContextMenu itself is a FrameworkElement derived class, but this event will not be raised from the context menu being opened as a source. The event is raised from the element that "owns" the context menu as a property and is only raised when a user attempts to open a context menu in the UI. It is possible for ContextMenu itself to have a ContextMenu property, but you should avoid this scenario (for details, see FrameworkElement.ContextMenu).
Available since 3.0