Condividi tramite


Classe MenuGroup

Aggiornamento: novembre 2007

Rappresenta un gruppo di voci di menu.

Spazio dei nomi:  Microsoft.Windows.Design.Interaction
Assembly:  Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)

Sintassi

Public Class MenuGroup _
    Inherits MenuBase

Dim instance As MenuGroup
public class MenuGroup : MenuBase
public ref class MenuGroup : public MenuBase
public class MenuGroup extends MenuBase

Note

Le voci di menu sono rappresentate dalla classe MenuAction. Un gruppo di menu può includere un insieme di voci di menu direttamente nel menu o come sottomenu, denominato anche menu a comparsa. Impostare la proprietà HasDropDown per visualizzare le voci di menu in un sottomenu.

Per visualizzare le voci di menu di scelta rapida, ereditare dalla classe PrimarySelectionContextMenuProvider e creare elementi MenuAction e un oggetto MenuGroup associato.

Esempi

Nell'esempio di codice seguente viene illustrato come configurare due elementi MenuAction e assegnarli a un oggetto MenuGroup. Per ulteriori informazioni, vedere Procedura dettagliata: creazione di una MenuAction.

' 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);
}

Gerarchia di ereditarietà

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

Codice thread safe

Qualsiasi membro static (Shared in Visual Basic) pubblico di questo tipo è thread-safe. I membri di istanza non sono garantiti come thread-safe.

Vedere anche

Riferimenti

Membri MenuGroup

Spazio dei nomi Microsoft.Windows.Design.Interaction

MenuAction

PrimarySelectionContextMenuProvider

Altre risorse

Procedura dettagliata: creazione di una MenuAction