How to add Menu Items and Sub Menus to a Menu

Now let's add menu items and sub menus to the menu control. The MenuItem tag adds a menu item to the menu control. The following code shows the initial syntax of the MenuItem tag. The Header attribute is the name of the MenuItem.

  <MenuItem Header="Menu Item Name " />    

A MenuItem can have other MenuItem tags within it as child/sub menus and can go up to several levels. The following code adds three children menu items to first menu item.

  <MenuItem Header="_File">          

            <MenuItem Header="_Open" IsCheckable="true"/>

            <MenuItem Header="_Close" IsCheckable="true"/>

            <MenuItem Header="_Save" IsCheckable="true"/>
  </MenuItem> 


A separate is used to separate categories of menu items. We can add a separator to a menu control by using <Separator /> tag. 

We can also ass sub menus and sub menu items using the MenuItem tag within parent a MenuItem tag. The following code adds a separator and sub menus and sub menu items to the menu.

<Separator/>

<MenuItem Header="Sub Items">

    <MenuItem Header="Child1 SubItem" IsCheckable="true"/>

    <MenuItem Header="Child2 SubItem" IsCheckable="true">

        <MenuItem Header="GrandChild2 SubItem" IsCheckable="true"/>

     </MenuItem>

</MenuItem>