Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkElement::ContextMenuClosing Event

Occurs just before any context menu on the element is closed.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public:
 event ContextMenuEventHandler^ ContextMenuClosing {
	void add (ContextMenuEventHandler^ value);
	void remove (ContextMenuEventHandler^ value);
}
<object ContextMenuClosing="ContextMenuEventHandler" .../>

Identifier field

ContextMenuClosingEvent

Routing strategy

Bubbling

Delegate

ContextMenuEventHandler

To suppress closing context menus, handlers of the event should mark it as handled.

To use this event as an EventTrigger in a style, you must reference the underlying service's definition of the event:

<EventTrigger RoutedEvent="ContextMenuService.ContextMenuClosing">
  <!-- storyboard here ... -->
</EventTrigger>

(This usage is required because the event implementation on FrameworkElement that exposes the underlying service event does not map the ContextMenuClosing identifier such that you can use it as a trigger).

ContextMenu itself is a FrameworkElement derived class, but the ContextMenuClosing event will not be raised by a context menu directly. Instead, the event is raised from the element that "owns" the context menu as a property and is only raised when a user attempts to close a context menu in the UI. However it is possible for ContextMenu itself to have a ContextMenu property (a nested context menu). In this case the ContextMenu really does own the nested ContextMenu and might raise the event, with the source of the event being the nested context menu.

The ContextMenu class itself also has a similar event (Closed) but the Closed event does not provide you the opportunity to cancel the user action.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft