2016-09-01 174 views
0

我想将一个子菜单添加到Visual Studio中的上下文菜单中。类似于ReSharper的作用: resharper submenu将子菜单添加到Visual Studio扩展中的上下文菜单中

我的设置如下: MyTopMenuGroup:包含Command1MyMenuController。 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显示为 “顶层” 命令。 其他命令和菜单根本不显示。

为什么菜单不显示,我怎样才能看到它?

+0

设置没问题,重新启动修复了我的问题。对于与此相关的其他人,我已经写了一篇关于如何将其归档的小介绍:https://blog.famoser.ch/visual-studio-extensions-commands/ –

回答

1

您的XAML看起来很好(我认为按钮和菜单实际上有字符串部分),并且Command3/Command4应该是可见的。只要确保它们具有像Command1一样的MenuItemCallbacks。

+0

你说得对,设置很好。有时你需要的只是重启。 –

相关问题