【发布时间】:2016-09-02 20:58:32
【问题描述】:
我想在 Visual Studio 的上下文菜单中添加一个子菜单。类似于 resharper 所做的:
我的设置如下:
MyTopMenuGroup:包含Command1 和MyMenuController。 MenuController 本身还有另一个组,其中包含一些其他命令。不幸的是,MenuController 没有显示出来。
我的 XAML:
<Groups>
<Group guid="mypkg" id="MyTopMenuGroup" >
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</Group>
<Group guid="mypkg" id="MySubMenuGroup">
<Parent guid="mypkg" id="MyMenuController" />
</Group>
</Groups>
<Menus>
<Menu guid="mypkg" id="MyMenuController" type="MenuController">
<Parent guid="mypkg" id="MyTopMenuGroup" />
</Menu>
</Menus>
<Buttons>
<Button guid="mypkg" id="Command1" type="Button">
<Parent guid="mypkg" id="MyTopMenuGroup" />
</Button>
<Button guid="mypkg" id="Command2" type="Button">
<Parent guid="mypkg" id="MyMenuController" />
</Button>
<Button guid="mypkg" id="Command3" type="Button">
<Parent guid="mypkg" id="MySubMenuGroup" />
</Button>
<Button guid="mypkg" id="Command4" type="Button">
<Parent guid="mypkg" id="MySubMenuGroup" />
</Button>
</Buttons>
将按钮添加到菜单的C#:
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, Command1);
var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
commandService.AddCommand(menuItem);
//etc, do this for all 4 Commands
//no code to construct groups & menus (is this necessary?)
}
Command1 按预期显示为“顶级”命令。 其他命令和菜单根本不显示。
为什么菜单不显示,如何使它可见?
【问题讨论】:
-
设置很好,重启解决了我的问题。对于其他为此苦苦挣扎的人,我写了一个关于如何存档的简短介绍:blog.famoser.ch/visual-studio-extensions-commands
标签: c# visual-studio-extensions