Reputation: 2663
I want to add a submenu to the context menu in Visual Studio. Similar to what resharper does:
My setup is as follows:
MyTopMenuGroup
: contains Command1
and MyMenuController
. The MenuController itself has again another group, which contains some other commands. Unfortunately the MenuController is not displayed.
My 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# which adds the buttons to the menu:
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 is displayed as "top-level" command as expected. The other commands and the Menu is not displayed at all.
Why is the Menu not shown and how can I make it visible?
Upvotes: 2
Views: 1347
Reputation: 27890
Your XAML looks fine (I presume Buttons and Menus actually have Strings sections) and Command3/Command4 should be visible. Just make sure they have MenuItemCallbacks attached like Command1.
Upvotes: 1