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.