开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜