Export (0) Print
Expand All
1 out of 4 rated this helpful - Rate this topic

Menu Class

Represents a Windows menu control that enables you to hierarchically organize elements associated with commands and event handlers.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public class Menu : MenuBase
public class Menu extends MenuBase
public class Menu extends MenuBase
<Menu>
  Items
</Menu>

Content Model: Menu is an ItemsControl. For more information on the content model for Menu, see ItemsControl Content Model.

The Menu control presents a list of items that specify commands or options for an application. Typically, clicking an item on a menu opens a submenu or causes an application to carry out a command.

An item in a menu can be anything that can be added to an ItemCollection. The MenuItem is the most common type of item in a Menu. A MenuItem can contain child items. The child items will appear in a submenu when the user chooses a parent MenuItem.

This example shows how to create Menu controls. The example illustrates Menu controls with submenus and MenuItem elements with ToolTip controls. The example also shows how to use the IsCheckable property to make MenuItem controls that can be checked.

<Menu Width="30" Margin="10, 10, 5, 5" HorizontalAlignment="Left" Background="White">
   <MenuItem Header="_File">
          <MenuItem Header="_New" IsCheckable="true"/>
          <MenuItem Header="_Open" IsCheckable="true"/>
          <MenuItem Header="_Close" IsCheckable="true"/>
	  <Separator/>
          <MenuItem Header="Menu with Submenu">
                <MenuItem Header="_submenuitem1" IsCheckable="true"/>
                <MenuItem Header="_submenuitem2" IsCheckable="true">          
                    <MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
                </MenuItem>
         </MenuItem>
         <Separator/>
         <MenuItem Header="_Menu item with ToolTip">
          <MenuItem.ToolTip>
            <ToolTip>
            ToolTip Information.
            </ToolTip>
          </MenuItem.ToolTip>
      </MenuItem>
   </MenuItem>
</Menu>

menu = new Menu();
menu.Background = Brushes.LightBlue;
mi = new MenuItem();
mi.Width = 50;
mi.Header = "_File";
menu.Items.Add(mi);

mia = new MenuItem();
mia.Header = "_Cut";
mia.InputGestureText = "Ctrl+X";
mi.Items.Add(mia);

mib = new MenuItem();
mib.Command = System.Windows.Input.ApplicationCommands.Copy;
mib.Header = "_Copy";
mi.Items.Add(mib);

mic = new MenuItem();
mic.Command = System.Windows.Input.ApplicationCommands.Paste;
mic.Header = "_Paste";
mi.Items.Add(mic);
cv2.Children.Add(menu);

For the complete sample, see Menu Sample.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
               System.Windows.Controls.ItemsControl
                 System.Windows.Controls.Primitives.MenuBase
                  System.Windows.Controls.Menu
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.