是否有可能在实施过程中添加菜单项的上下文菜单? [英] Is it possible to add Menu Items to a context menu during implementation?
本文介绍了是否有可能在实施过程中添加菜单项的上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我问正确的问题,但这里是我的处境。我有一个树型视图
,我正在实现。里面我设置/添加各种属性,其中一个是文本菜单
。所有我想要做的就是添加的MenuItems
到文本菜单
不传递到职能和
I hope I asked the right question, but here's my situation. I have a TreeViewItem
that I'm implementing. Inside it I set/add various properties, one of them being a ContextMenu
. All I want to do is add MenuItems
to the ContextMenu
without passing to functions and such.
下面是我如何实现我的树型视图
与文本菜单
:
Here's how I implement my TreeViewItem
with ContextMenu
:
public static TreeViewItem Item = new TreeViewItem() //Child Node
{
ContextMenu = new ContextMenu //CONTEXT MENU
{
Background = Brushes.White,
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1),
//**I would like to add my MENUITEMS here if possible
}
};
非常感谢!
Thanks a lot!
推荐答案
Sonhja答案是正确的。为您的情况为例。
Sonhja answer is correct. Providing a example for your case.
TreeViewItem GreetingItem = new TreeViewItem()
{
Header = "Greetings",
ContextMenu = new ContextMenu //CONTEXT MENU
{
Background = Brushes.White,
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1),
}
};
MenuItem sayGoodMorningMenu = new MenuItem() { Header = "Say Good Morning" };
sayGoodMorningMenu.Click += (o, a) =>
{
MessageBox.Show("Good Morning");
};
MenuItem sayHelloMenu = new MenuItem() { Header = "Say Hello" };
sayHelloMenu.Click += (o, a) =>
{
MessageBox.Show("Hello");
};
GreetingItem.ContextMenu.Items.Add(sayHelloMenu);
GreetingItem.ContextMenu.Items.Add(sayGoodMorningMenu);
this.treeView.Items.Add(GreetingItem);
这篇关于是否有可能在实施过程中添加菜单项的上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文