Nishant
Nishant

Reputation: 453

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="TestContextMenu" >
        <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.

Upvotes: 0

Views: 347

Answers (2)

MBen
MBen

Reputation: 3996

Try this:

<MenuItem Header="Item 4" StaysOpenOnClick="True">

        <MenuItem.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Remove from List" Click="subMenuRemove_Click" />
            </ContextMenu>
        </MenuItem.ContextMenu>
</MenuItem>

Upvotes: 0

brunnerh
brunnerh

Reputation: 184296

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.

Upvotes: 2

Related Questions