TextBoxBase.OnContextMenuOpening(ContextMenuEventArgs) 方法


只要未处理的 ContextMenuOpening 路由事件在其路由中到达此类,就会调用此方法。Called whenever an unhandled ContextMenuOpening routed event reaches this class in its route. 实现此方法可为此事件添加类处理。Implement this method to add class handling for this event.

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



事件参数。Arguments of the event.



此方法没有默认实现。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 lets you handle the matching event from derived classes by using 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 might have been raised by a child element, which is not necessarily the element that invokes handlers. 因此, 您的实现需要考虑事件参数的源属性 (在大多数情况下, 不应尝试重新引发该事件)。Therefore, your implementation needs to take the event arguments' source properties into account (and should not try to re-raise the event in most cases). 当沿TextBoxBase路由接收事件时, 的子类可以调用私有类处理程序方法。Subclasses of TextBoxBase can call private class handler methods when the event is received along the route. 一种方案是采用事件的参数, 并特意将事件标记为已处理。One scenario is to take the arguments of the event and deliberately mark the event as handled.