简体   繁体   English

WPF ComboBox中的级联ContextMenu

[英]Cascaded ContextMenu in WPF ComboBox

I want to create a ComboBox that lets users select items the way the Windows XP start menu allows to select programs: 我想创建一个ComboBox ,让用户以Windows XP开始菜单允许选择程序的方式选择项目:

Is there a way to insert a cascaded ContextMenu inside a ComboBox ? 有没有办法在ComboBox插入级联的ContextMenu

I tried this but it doesn't work properly: 我试过了,但是不能正常工作:

<ComboBox>
        <MenuItem Header="Top Level 1">
            <MenuItem Header="Sub Level" />
            <MenuItem Header="Sub Level" />
        </MenuItem>
        <MenuItem Header="Top Level 2">
            <MenuItem Header="Sub Level" />
            <MenuItem Header="Sub Level" />
        </MenuItem>
</ComboBox>

You will want to try somthing like this, The next level must be inside the first level. 您将要尝试这样的事情,下一个级别必须在第一个级别内。

<Menu Margin="0,0,0,283">
    <MenuItem Header="Top Level 1">
        <MenuItem Header="Sub Level" />
        <MenuItem Header="Sub Level" />
        <MenuItem Header="Top Level 2">
            <MenuItem Header="Sub Level" />
            <MenuItem Header="Sub Level" />
            <MenuItem Header="Top Level 3">
                <MenuItem Header="Sub Level" />
                <MenuItem Header="Sub Level" />
            </MenuItem>
        </MenuItem>
    </MenuItem>
</Menu>

在此处输入图片说明

Do you have to use a ComboBox? 您必须使用ComboBox吗?

Using the Menu control will make your MenuItems work easily... so I would use that instead: http://wpftutorial.net/Menus.html 使用Menu控件将使您的MenuItems轻松工作...所以我会改用它: http : //wpftutorial.net/Menus.html

You can always alter the look of it as well. 您也可以随时更改其外观。 There are some examples here: http://www.c-sharpcorner.com/uploadfile/mahesh/menus-in-wpf/ 这里有一些示例: http : //www.c-sharpcorner.com/uploadfile/mahesh/menus-in-wpf/

Else, did you try to wrap your menuitems in a simply? 否则,您是否尝试过将菜单项简单地包装起来?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM