Elmo
Elmo

Reputation: 6471

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:

Is there a way to insert a cascaded ContextMenu inside a ComboBox?

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>

Upvotes: 2

Views: 1703

Answers (2)

sa_ddam213
sa_ddam213

Reputation: 43596

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>

enter image description here

Upvotes: 1

Joe
Joe

Reputation: 2564

Do you have to use a ComboBox?

Using the Menu control will make your MenuItems work easily... so I would use that instead: 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/

Else, did you try to wrap your menuitems in a simply?

Upvotes: 0

Related Questions