手动引发ContextMenuClosing事件

时间:2010-07-05 18:35:35

标签: wpf routed-events

我是从ContextMenu派生的,在派生类中我需要手动引发ContextMenuClosing事件。我尝试了以下两种方式:

// On runtime tells me it can't convert from  
// "System.Windows.RoutedEventArgs" to 
// "System.Windows.Controls.ContextMenuEventArgs"
RaiseEvent(new RoutedEventArgs(ContextMenuClosingEvent));

// Second attempt: On compile time tells me,
// there's no constructor for ContextMenuEventArgs
OnContextMenuClosing(new ContextMenuEventArgs());

我是RoutedEvents的新手,有人可以帮我解决如何手动提升ContextMenuClosing事件的问题吗?谢谢!

1 个答案:

答案 0 :(得分:0)

this question中,海报展示了他似乎能够实例化ContextMenuEventArgs的代码,即使它的构造函数是私有的