我想将一个子菜单添加到Visual Studio中的上下文菜单中。类似于ReSharper的作用: 将子菜单添加到Visual Studio扩展中的上下文菜单中
我的设置如下: 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显示为 “顶层” 命令。 其他命令和菜单根本不显示。
为什么菜单不显示,我怎样才能看到它?
设置没问题,重新启动修复了我的问题。对于与此相关的其他人,我已经写了一篇关于如何将其归档的小介绍:https://blog.famoser.ch/visual-studio-extensions-commands/ –