共用方式為


MenuGroup 類別

表功能表項目群組。

繼承階層架構

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

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

語法

'宣告
Public Class MenuGroup _
    Inherits MenuBase
public class MenuGroup : MenuBase
public ref class MenuGroup : public MenuBase
type MenuGroup =  
    class
        inherit MenuBase
    end
public class MenuGroup extends MenuBase

MenuGroup 型別會公開下列成員。

建構函式

  名稱 說明
公用方法 MenuGroup(String) 初始化 MenuGroup 類別的新執行個體,這個類別有指定的群組名稱。
公用方法 MenuGroup(String, String) 初始化 MenuGroup 類別的新執行個體,這個類別具有指定的群組名稱和顯示名稱。

回頁首

屬性

  名稱 說明
公用屬性 Context 取得目前的編輯內容。 (繼承自 MenuBase)。
公用屬性 DisplayName 取得或設定在功能表項目上顯示的當地語系化文字。 (繼承自 MenuBase)。
公用屬性 HasDropDown 取得或設定值,這個值表示是否要將 Items 集合中的功能表項目加入至子功能表。
公用屬性 Items 取得要在相同的功能表群組中顯示為同層級 (Sibling) 的功能表項目清單。
公用屬性 Name 取得或設定功能表項目的唯一識別項。 (繼承自 MenuBase)。

回頁首

方法

  名稱 說明
公用方法 Equals 判斷指定的 Object 和目前的 Object 是否相等。 (繼承自 Object)。
受保護的方法 Finalize 允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。 (繼承自 Object)。
公用方法 GetHashCode 做為特定型別的雜湊函式。 (繼承自 Object)。
公用方法 GetType 取得目前執行個體的 Type。 (繼承自 Object)。
受保護的方法 MemberwiseClone 建立目前 Object 的淺層複本 (Shallow Copy)。 (繼承自 Object)。
受保護的方法 OnPropertyChanged 引發 PropertyChanged 事件。 (繼承自 MenuBase)。
公用方法 ToString 傳回表示目前物件的字串。 (繼承自 Object)。

回頁首

事件

  名稱 說明
公用事件 PropertyChanged 發生於屬性變更時。 (繼承自 MenuBase)。

回頁首

備註

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

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

範例

下列程式碼範例說明如何設定兩個 MenuAction 項目,並將它們指派給 MenuGroup。 如需詳細資訊,請參閱逐步解說:建立功能表提供者

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

執行緒安全

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

請參閱

參考

Microsoft.Windows.Design.Interaction 命名空間

MenuAction

PrimarySelectionContextMenuProvider

其他資源

逐步解說:建立功能表提供者