---
title: "Menu Control in WPF"  
description: "In XAML  and  tag elements is used to create a menu control in WPF. Menus have been an integral part of any windows based application. In WPF there ar"  
author: "Anonymous User"  
published: 2011-04-06  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/539/menu-control-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 4 minutes  

---

# Menu Control in WPF

In XAML <Menu /> and <[MenuItem](https://www.mindstick.com/forum/23048/menuitem-call-javascript-function) /> tag [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) is used to create a [menu control](https://www.mindstick.com/interview/2227/what-does-the-orientation-property-do-in-a-menu-control) in WPF. Menus have been an integral part of any windows based application. In WPF there are two classes that are used for making menus. Menu and MenuItem class. A menu is [collection](https://www.mindstick.com/articles/1718/collections-in-java) of menu items with a command associated with each menu items. In this [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) I will show you that how to use Menu control in WPF.\

##### Some major properties associated with menu control

- **Name**—Name [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) defines a unique name to your WPF menu control.
- **Height**—Height property is used to set height of your menu control in WPF.
- **Width**—Width property is used to set Width of your menu control.
- **Margin**—Margin property is used to define margin of your menu control.
- **[Background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp)**—Background property defines background of your menu control.
- **HorizontalAlignment**—HorizontalAlignment property is used to define horizontal alignment of your menu control in side [container](https://www.mindstick.com/forum/34127/extjs-how-to-set-border-for-the-container) control.
- **VerticalAlignment**—VerticalAlignment property is used to define [vertical](https://www.mindstick.com/forum/12951/how-to-fix-bootstrap-tab-vertical-with-text) alignment of your menu control.
- **ToolTip**—ToolTip defines tooltip for your menu control.

##### The following code snippet create a menu control in WPF

```
<Menu Width="500" Height="30" HorizontalAlignment="Left" VerticalAlignment="Top">            <Menu.BitmapEffect>                <DropShadowBitmapEffect />            </Menu.BitmapEffect>            <Menu.Background>                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">                    <GradientStop Color="Black" Offset="1" />                    <GradientStop Color="#B774B19B" Offset="0.455" />                </LinearGradientBrush>            </Menu.Background></Menu>
```

##### Output of the following code snippet

![Menu control in WPF](https://www.mindstick.com/mindstickarticle/91ec7c15-c848-423c-9dfc-0609015210e1/images/4979531b-4617-4e45-a409-0491d36b90ac.png)

##### Adding menu items and submenu items to a menu control

After adding Menu control in window the next step is to create a menu item and sub menu item in menu control. We can use <MenuItem /> element in XAML to create a menu item and use Header property of menu Item control to provide a caption to menu item control. The following code snippet represents use of menu item control in WPF.

##### A XAML code for adding menu items in menu

```
<MenuItem Header="_File" >                <MenuItem Header="New" />                <MenuItem Header="Open" />                <MenuItem Header="Close" />            </MenuItem>            <MenuItem Header='_Edit'>                <MenuItem Header="Undo" />                <MenuItem Header="Redo" />                <MenuItem Header="Cut" />                <MenuItem Header="Copy" />                <MenuItem Header="Paste" />                <MenuItem Header="Select All" /></MenuItem>
```

##### Output of the following code is as follows

![Menu control in WPF](https://www.mindstick.com/mindstickarticle/91ec7c15-c848-423c-9dfc-0609015210e1/images/0e0282ec-d49e-4ab0-a108-8195e90c4ca2.png)

We can add separator control to create a grouping in menu items. The following XAML element is used to create a separator <Separator />.

##### Following code snippet represents use of separator control

```
<MenuItem Header='_Edit'>                <MenuItem Header="Undo" />                <MenuItem Header="Redo" />                <Separator />                <MenuItem Header="Cut" />                <MenuItem Header="Copy" />                <MenuItem Header="Paste" />                <Separator />                <MenuItem Header="Select All" />            </MenuItem></Menu>
```

##### Output of the following code snippet is as follows

![Menu control in WPF](https://www.mindstick.com/mindstickarticle/91ec7c15-c848-423c-9dfc-0609015210e1/images/65ecf574-53b0-4417-9456-508cf962efcc.png)

##### Adding tooltips in menu item

We can use tool tip to give some useful information about menu item control. In XAML <MenuItem.ToolTip /> container element is used to create a ToolTip for menu item.

##### Following demonstration shows how to use tooltip for menu item.

```
<MenuItem Header="_File" >                <MenuItem Header="New" >                    <MenuItem.ToolTip>                        <ToolTip>Create a new file.</ToolTip>                    </MenuItem.ToolTip>                </MenuItem>                <MenuItem Header="Open" >                    <MenuItem.ToolTip>                        <ToolTip>                            Open an existing file.                        </ToolTip>                    </MenuItem.ToolTip>                </MenuItem>                <Separator />                <MenuItem Header="Close" >                    <MenuItem.ToolTip>                        <ToolTip>                            Close an existing file.                        </ToolTip>                    </MenuItem.ToolTip>                </MenuItem> </MenuItem>
```

##### Output of the following code snippet is as follows

![Menu control in WPF](https://www.mindstick.com/mindstickarticle/91ec7c15-c848-423c-9dfc-0609015210e1/images/ee46e7f3-4711-461d-a3f4-ab326fd9b351.png)

##### Responding to a click event in menu item of a menu control

```
<MenuItem Header="_File" >                <MenuItem Header="New" Click="MenuItem_Click" >                    <MenuItem.ToolTip>                        <ToolTip>Create a new file.</ToolTip>                    </MenuItem.ToolTip>                </MenuItem>                <MenuItem Header="Open" Click="MenuItem_Click" >                    <MenuItem.ToolTip>                        <ToolTip>                            Open an existing file.                        </ToolTip>                    </MenuItem.ToolTip>                </MenuItem>                <Separator />                <MenuItem Header="Close" Click="MenuItem_Click" >                    <MenuItem.ToolTip>                        <ToolTip>                            Close an existing file.                        </ToolTip>                    </MenuItem.ToolTip></MenuItem>
```

##### Output of the following code snippet is as follows

![Menu control in WPF](https://www.mindstick.com/mindstickarticle/91ec7c15-c848-423c-9dfc-0609015210e1/images/b35445c0-e354-4511-84b8-3e9dfa8dda9c.png)

---

Original Source: https://www.mindstick.com/articles/539/menu-control-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
