FrameworkElement.ContextMenuClosing Event


在元素上的任何上下文菜单关闭之前发生。Occurs just before any context menu on the element is closed.

 event System::Windows::Controls::ContextMenuEventHandler ^ ContextMenuClosing;
public event System.Windows.Controls.ContextMenuEventHandler ContextMenuClosing;
member this.ContextMenuClosing : System.Windows.Controls.ContextMenuEventHandler 
Public Custom Event ContextMenuClosing As ContextMenuEventHandler 


若要取消关闭上下文菜单,该事件的处理程序应将其标记为已处理。To suppress closing context menus, handlers of the event should mark it as handled.

若要使用此事件作为样式中的 EventTrigger,必须引用事件的基础服务定义: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 ... -->

(这种用法是必需的,因为公开基础服务事件 FrameworkElement 上的事件实现不会映射 ContextMenuClosing 标识符,因此你可以将其用作触发器)。(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 本身是一个 FrameworkElement 派生类,但 ContextMenuClosing 事件不会直接由上下文菜单引发。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. ContextMenu 本身有可能具有 ContextMenu 属性(一个嵌套上下文菜单)。However it is possible for ContextMenu itself to have a ContextMenu property (a nested context menu). 在这种情况下,ContextMenu 确实拥有嵌套 ContextMenu,可能引发事件,并将事件的源作为嵌套上下文菜单。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.

ContextMenu 类本身也具有类似的事件(Closed),但 Closed 事件不会为你提供取消用户操作的机会。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.

路由事件信息Routed Event Information

标识符字段Identifier field ContextMenuClosingEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate ContextMenuEventHandler

Applies to

See also