FrameworkElement.OnContextMenuOpening(ContextMenuEventArgs) 方法


當未處理的 ContextMenuOpening 路由事件到達其路由中的這個類別時,便會叫用此方法。Invoked whenever an unhandled ContextMenuOpening routed event reaches this class in its route. 實作這個方法可為此事件加入類別處理。Implement this method to add class handling for this event.

 virtual void OnContextMenuOpening(System::Windows::Controls::ContextMenuEventArgs ^ e);
protected virtual void OnContextMenuOpening (System.Windows.Controls.ContextMenuEventArgs e);
abstract member OnContextMenuOpening : System.Windows.Controls.ContextMenuEventArgs -> unit
override this.OnContextMenuOpening : System.Windows.Controls.ContextMenuEventArgs -> unit
Protected Overridable Sub OnContextMenuOpening (e As ContextMenuEventArgs)



包含事件資料的 RoutedEventArgsThe RoutedEventArgs that contains the event data.


這個方法沒有預設的實值。This method has no default implementation. 當繼承中的中繼類別已實作為此方法時,您仍然應該呼叫基底實作為。You should still call the base implementation in case an intermediate class in the inheritance has implemented this method.

這個方法的用途與 通用語言執行平台 (CLR)common language runtime (CLR) * 方法上的事件模式有點類似:它提供了使用類別處理常式而非實例處理常式來處理衍生類別中相符事件的方法。The purpose of this method is somewhat similar to 通用語言執行平台 (CLR)common language runtime (CLR) event pattern On* methods: it provides the means to handle the matching event from derived classes with a class handler instead of an instance handler. 在此情況下,比對事件是路由事件。In this case the matching event is a routed event. 因為路由事件可能是由子項目引發,而不一定是將叫用處理程式的專案,) (所以 On * 方法的真實模式與路由事件不同,因為路由事件可能是由子項目引發,而不一定是將叫用處理程式的元素The implementation pattern of the On* methods is different for routed events because the routed event may have been raised by a child element, not necessarily the element that will invoke handlers, so your implementation will need to take the event arguments' source properties into account (and should not try to re-raise the event in most cases). 的子類別 FrameworkElement 可選擇在路由接收事件時呼叫私用類別處理常式方法。Subclasses of FrameworkElement could choose to call private class handler methods when the event is received along the route. 其中一個可能的情況是採用事件的引數,並刻意將事件標示為已處理。One potential scenario is to take the arguments of the event and deliberately mark the event as handled.