How to Add SubMenus in Menu control: WPF

What will be the use of Menu control if we add only one line menus like in our previous post? Menu control is used to organize elements in hierarchy view. In previous post we have added some menu items, in this post we will add some child elements in those elements.

Just use the below lines of code in XAML to generate a menu control with some child elements:
<Menu IsMainMenu="True">
<MenuItem Header="_First">
<MenuItem Header="Child 1"></MenuItem>
<MenuItem Header="Child 2"></MenuItem>
<MenuItem Header="Child 3"></MenuItem>
<MenuItem Header="_Second">
<MenuItem Header="Child 4"></MenuItem>
<MenuItem Header="Child 5"></MenuItem>
<MenuItem Header="Child 6"></MenuItem>
<MenuItem Header="_Third">
<MenuItem Header="Child 7"></MenuItem>
<MenuItem Header="Child 8"></MenuItem>

It will add three children to first element, three to second element and two to third element. The image shows the first three:

How to add Submenu and expand them WPF

Menu control provides a checkbox feature with each of the item, that can be enable using IsCheckable property to true. After enable the items cab be checked individually like:

How to create a checkable menus in WPF


Post a Comment