This topic has not yet been rated - Rate this topic

MenuGroup Class

Represents a group of menu items.

System.Object
  Microsoft.Windows.Design.Interaction.MenuBase
    Microsoft.Windows.Design.Interaction.MenuGroup

Namespace:  Microsoft.Windows.Design.Interaction
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)
public class MenuGroup : MenuBase

The MenuGroup type exposes the following members.

  NameDescription
Public methodMenuGroup(String)Initializes a new instance of the MenuGroup class that has the specified group name.
Public methodMenuGroup(String, String)Initializes a new instance of the MenuGroup class that has the specified group name and display name.
Top
  NameDescription
Public propertyContextGets the current editing context. (Inherited from MenuBase.)
Public propertyDisplayNameGets or sets the localized text to display for the menu item. (Inherited from MenuBase.)
Public propertyHasDropDownGets or sets a value indicating whether the menu items in the Items collection are added to a submenu.
Public propertyItemsGets a list of menu items to display as siblings within the same menu group.
Public propertyNameGets or sets the unique identifier for the menu item. (Inherited from MenuBase.)
Top
  NameDescription
Public methodEqualsDetermines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnPropertyChangedRaises the PropertyChanged event. (Inherited from MenuBase.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public eventPropertyChangedOccurs when a property has changed. (Inherited from MenuBase.)
Top

Menu items are represented by the MenuAction class. A menu group can have a collection of menu items directly on the menu or as a submenu, which is also called a flyout menu. Set the HasDropDown property to display menu items in a submenu.

To show context menu items, inherit from the PrimarySelectionContextMenuProvider class and create MenuAction items and an associated MenuGroup.

The following code example shows how to set up two MenuAction items and assign them to a MenuGroup. For more information, see Walkthrough: Creating a Menu Provider.


// The provider's constructor sets up the MenuAction objects 
// and the the MenuGroup which holds them.
public CustomContextMenuProvider()
{   
    // Set up the MenuAction which sets the control's 
    // background to Blue.
    setBackgroundToBlueMenuAction = new MenuAction("Blue");
    setBackgroundToBlueMenuAction.Checkable = true;
    setBackgroundToBlueMenuAction.Execute += 
        new EventHandler<MenuActionEventArgs>(SetBackgroundToBlue_Execute);

    // Set up the MenuAction which sets the control's 
    // background to its default value.
    clearBackgroundMenuAction = new MenuAction("Cleared");
    clearBackgroundMenuAction.Checkable = true;
    clearBackgroundMenuAction.Execute += 
        new EventHandler<MenuActionEventArgs>(ClearBackground_Execute);

    // Set up the MenuGroup which holds the MenuAction items.
    MenuGroup backgroundFlyoutGroup = 
        new MenuGroup("SetBackgroundsGroup", "Set Background");

    // If HasDropDown is false, the group appears inline, 
    // instead of as a flyout. Set to true.
    backgroundFlyoutGroup.HasDropDown = true;
    backgroundFlyoutGroup.Items.Add(setBackgroundToBlueMenuAction);
    backgroundFlyoutGroup.Items.Add(clearBackgroundMenuAction);
    this.Items.Add(backgroundFlyoutGroup);

    // The UpdateItemStatus event is raised immediately before 
    // this provider shows its tabs, which provides the opportunity 
    // to set states.
    UpdateItemStatus += 
        new EventHandler<MenuActionEventArgs>(
            CustomContextMenuProvider_UpdateItemStatus);
}


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.