FrameworkContentElement.ContextMenuOpening 事件


當項目上的任何內容功能表開啟時發生。Occurs when any context menu on the element is opened.

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


若要手動開啟操作功能表,事件的處理常式應該將相關事件標示為已處理。To manually open context menus, handlers of the events should mark the relevant event as handled. 否則,會使用 ContextMenu 屬性的現有值來自動開啟內容功能表。Otherwise, the existing value of the ContextMenu property will be used to automatically open a context menu. 將事件標示為已處理,會有效地取消預設動作,而且可能會有機會重設 ContextMenu 屬性的值,然後開啟新的 ContextMenuMarking 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. 若要透過 ContextMenuOpening 處理常式完全取代內容功能表,初始內容功能表不得為 null/空白。In order to completely replace the context menu through a ContextMenuOpening 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. 如需詳細資訊,請參閱如何:處理 CoNtextMenuOpening 事件For details, see How to: Handle the ContextMenuOpening Event.

若要使用此事件做為樣式中的 EventTrigger,您必須參考基礎服務事件識別碼:To use this event as an EventTrigger in a style, you must reference the underlying service event identifier:

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

(這是必要的用法,因為公開基礎服務事件之 FrameworkContentElement 上的事件執行,並未正確對應 ContextMenuOpening 識別碼以用於觸發程式)。(This usage is required because the event implementation on FrameworkContentElement that exposes the underlying service event does not correctly map the ContextMenuOpening identifier for use in triggers).

路由事件資訊Routed Event Information

識別碼欄位Identifier field ContextMenuOpeningEvent
路由策略Routing strategy 路由Bubbling
Delegate - 委派Delegate ContextMenuEventHandler