System.Windows ContextMenu ItemClick事件? [英] System.Windows ContextMenu ItemClick Event?

查看:43
本文介绍了System.Windows ContextMenu ItemClick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作WPF应用程序,但是在我的代码中我需要制作一个ContextMenu,这看起来真的很简单:

I'm making a WPF application, but in my code I need to make a ContextMenu, it seemed really easy:

_menu = new ContextMenu();
_menu.Items.Add("My menu item");

然后我用了它,所有东西都像个护身符.

Then I used it, and everything works like a charm.

但是,我需要知道何时单击我的菜单项",但是我似乎找不到正确的事件,我正在搜索类似ItemClick事件的东西,但找不到它...

However, I need to know when "My menu item" is clicked, but I can't seem to find the right event, I'm searching for something like ItemClick event, but cant't find it...

推荐答案

尝试添加可单击的项目,而不只是字符串.例如:

Try adding an item that is clickable rather than just a string. For example:

_menu = new ContextMenu();
MenuItem item = new MenuItem();
item.Click += MyClickHandler;
item.Header = "My Menu Item";
_menu.Items.Add(item);

这篇关于System.Windows ContextMenu ItemClick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆