手动引发 ContextMenuClosing 事件

发布于 2024-09-08 10:02:13 字数 508 浏览 3 评论 0原文

我从 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 事件吗?谢谢!

I'm deriving from ContextMenu and inside the derived class I need to raise the ContextMenuClosing event manually. I tried the following two ways:

// 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());

I'm new to RoutedEvents, can someone please help me how to raise the ContextMenuClosing event manually? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪之魂 2024-09-15 10:02:13

这个问题中,海报显示了他似乎能够使用的代码实例化 ContextMenuEventArgs,即使它的构造函数是私有的

In this question the poster shows code in which he seems to be able to instantiate ContextMenuEventArgs even though its constructor is private

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文