ContextMenu within another ContextMenu
Is it possible to put a ContextMenu within another ContextMenu? I have code to display a ContextMenu on the click of a button and a click event attached with this ContextMenu. Now, I want to display another ContextMenu on the right-click of any item in the main ContextMenu. I tried the following code but it doesn't work:
<Button.ContextMenu>
<ContextMenu Name="Te开发者_如何学运维stContextMenu" >
<MenuItem Header="Item 1" StaysOpenOnClick="True" />
<MenuItem Header="Item 2" StaysOpenOnClick="True" />
<MenuItem Header="Item 3" StaysOpenOnClick="True" />
<MenuItem Header="Item 4" StaysOpenOnClick="True" />
<ContextMenu.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove from List" Click="subMenuRemove_Click" />
</ContextMenu>
</ContextMenu.ContextMenu>
</ContextMenu>
</Button.ContextMenu>
Even adding ContextMenu to each Menu Item (MenuItem.ContextMenu) doesn't work.
Who would even try to right click a menu item and expect it to have a context-menu? Maybe that is why this is not possible, either way, i greatly recommend not doing this as it breaks common conventions.
Maybe add a menu-configuration dialog instead, or one MenuItem at the end which allows removal by item.
Try this:
<MenuItem Header="Item 4" StaysOpenOnClick="True">
<MenuItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove from List" Click="subMenuRemove_Click" />
</ContextMenu>
</MenuItem.ContextMenu>
</MenuItem>
精彩评论