共用方式為


MenuGroup 類別

更新:2007 年 11 月

表示一組功能表項目。

命名空間:  Microsoft.Windows.Design.Interaction
組件:  Microsoft.Windows.Design.Extensibility (在 Microsoft.Windows.Design.Extensibility.dll 中)

語法

Public Class MenuGroup _
    Inherits MenuBase

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

備註

功能表項目是由 MenuAction 類別所表示。功能表群組可以直接將功能表項目集合直接置於功能表上,或是當做子功能表,這也稱為「延伸式」(Flyout) 功能表。您可以設定 HasDropDown 屬性,在子功能表中顯示功能表項目。

若要顯示內容功能表項目,請繼承自 PrimarySelectionContextMenuProvider 類別,並建立 MenuAction 項目與相關聯的 MenuGroup。

範例

在下列程式碼範例中,會說明如何設定兩個 MenuAction 項目,並將它們指派給 MenuGroup。如需詳細資訊,請參閱逐步解說:建立 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);
}

繼承階層架構

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

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

MenuGroup 成員

Microsoft.Windows.Design.Interaction 命名空間

MenuAction

PrimarySelectionContextMenuProvider

其他資源

逐步解說:建立 MenuAction