Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
/** @event */ public void add_ContextMenuOpening (ContextMenuEventHandler value) /** @event */ public void remove_ContextMenuOpening (ContextMenuEventHandler value)
In JScript, you can handle the events defined by a class, but you cannot define your own.
To manually open context menus, handlers of the events should mark the relevant event as handled. Otherwise, the 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.
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 ContextMenuOpening 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).
The ContextMenu class itself also has a similar event (Opened) but Opened does not provide you the opportunity to cancel the user action.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.