FrameworkElement.ContextMenuOpening FrameworkElement.ContextMenuOpening FrameworkElement.ContextMenuOpening FrameworkElement.ContextMenuOpening Event

定義

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

public:
 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 attached event:

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

(這種用法是必要的因為上的事件實作FrameworkElement,會公開基礎服務事件不會對應ContextMenuOpening識別項,您可以在觸發程序中使用它)。(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 本身是FrameworkElement衍生類別,但不是會從內容功能表中開啟做為來源引發此事件。ContextMenu itself is a FrameworkElement derived class, but this event will not be raised from the context menu being opened as a source. 從 「 擁有 」 做為屬性的內容功能表,並只會在使用者嘗試在 UI 中,開啟操作功能表時所引發的項目,會引發事件。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. 可能ContextMenu本身能夠ContextMenu屬性,但您應該避免這種情況 (如需詳細資訊,請參閱FrameworkElement.ContextMenu)。It is possible for ContextMenu itself to have a ContextMenu property, but you should avoid this scenario (for details, see FrameworkElement.ContextMenu).

ContextMenu類別本身也有類似的事件 (Opened),但Opened將不提供取消的使用者動作的機會。The ContextMenu class itself also has a similar event (Opened) but Opened does not provide you the opportunity to cancel the user action.

路由事件資訊Routed Event Information

識別項欄位Identifier field ContextMenuOpeningEvent
路由策略Routing strategy 事件反昇Bubbling
Delegate - 委派Delegate ContextMenuEventHandler

適用於

另請參閱