Share via


MenuGroup.HasDropDown Property

Gets or sets a value indicating whether the menu items in the Items collection are added to a submenu.

Namespace:  Microsoft.Windows.Design.Interaction
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)

Syntax

'Declaration
Public Property HasDropDown As Boolean
    Get
    Set
public bool HasDropDown { get; set; }
public:
property bool HasDropDown {
    bool get ();
    void set (bool value);
}
member HasDropDown : bool with get, set
function get HasDropDown () : boolean
function set HasDropDown (value : boolean)

Property Value

Type: System.Boolean
true if the menu items in the items collection will be added to a submenu; false if the items in the collection will be added directly to the current menu, rendered with a separator on each end.

Remarks

If HasDropDown equals true, the menu items in the items collection are added to a submenu. A menu item that has the DisplayName property set to the MenuGroup is added to the current menu and the menu items are added to a submenu. If HasDropDown equals false, the menu items in the collection are added directly to the current menu, rendered with a separator on both ends. For example, consider a menu group named Layout, with menu items Align Left and Align Right. If HasDropDown equals true, a Layout menu will added to the current menu with submenu items Align Left and Align Right. If HasDropDown equals false, Align Left and Align Right will be added to the current menu with a separator before Align Left and a separator after Align Right.

Examples

The following code example shows how to set up two MenuAction items and assign them to a MenuGroup. The HasDropDown property is set to true to enable flyout behavior. 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 Sub New()

    ' Set up the MenuAction which sets the control's 
    ' background to Blue.
    setBackgroundToBlueMenuAction = New MenuAction("Blue")
    setBackgroundToBlueMenuAction.Checkable = True
    AddHandler setBackgroundToBlueMenuAction.Execute, AddressOf SetBackgroundToBlue_Execute

    ' Set up the MenuAction which sets the control's 
    ' background to its default value.
    clearBackgroundMenuAction = New MenuAction("Cleared")
    clearBackgroundMenuAction.Checkable = True
    AddHandler clearBackgroundMenuAction.Execute, AddressOf ClearBackground_Execute

    ' Set up the MenuGroup which holds the MenuAction items.
    Dim backgroundFlyoutGroup As 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)
    Me.Items.Add(backgroundFlyoutGroup)

    ' The UpdateItemStatus event is raised immediately before 
    ' this provider shows its tabs, which provides the opportunity 
    ' to set states.
    AddHandler UpdateItemStatus, AddressOf CustomContextMenuProvider_UpdateItemStatus

End Sub
// 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);
}

.NET Framework Security

See Also

Reference

MenuGroup Class

Microsoft.Windows.Design.Interaction Namespace

MenuAction

PrimarySelectionContextMenuProvider

Other Resources

Walkthrough: Creating a Menu Provider