MenuGroup.HasDropDown 属性

更新:2007 年 11 月

获取或设置一个值,该值指示是否将 Items 集合中的菜单项添加到子菜单中。

命名空间:  Microsoft.Windows.Design.Interaction
程序集:  Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)

语法

声明
Public Property HasDropDown As Boolean
用法
Dim instance As MenuGroup
Dim value As Boolean

value = instance.HasDropDown

instance.HasDropDown = value
public bool HasDropDown { get; set; }
public:
property bool HasDropDown {
    bool get ();
    void set (bool value);
}
public function get HasDropDown () : boolean
public function set HasDropDown (value : boolean)

属性值

类型:System.Boolean

如果要将项集合中的菜单项添加到子菜单中,则为 true;如果要将集合中的项直接添加到当前菜单中,在每端用分隔符来呈现,则为 false。

备注

如果 HasDropDown 等于 true,则将项集合中的菜单项添加到子菜单中。DisplayName 属性设置为 MenuGroup 的菜单项将添加到当前菜单中,菜单项将添加到子菜单中。如果 HasDropDown 等于 false,则将集合中的菜单项直接添加到当前菜单中,并在两端用分隔符来呈现。例如,请考虑一个名为“布局”、具有“左对齐”和“右对齐”菜单项的菜单组。如果 HasDropDown 等于 true,则将向当前菜单中添加一个“布局”菜单,该菜单具有子菜单项“左对齐”和“右对齐”。如果 HasDropDown 等于 false,则将向当前菜单中添加“左对齐”和“右对齐”,在“左对齐”之前和“右对齐”之后各有一个分隔符。

示例

下面的代码示例演示如何设置两个 MenuAction 项并将其分配给 MenuGroup。通过将 HasDropDown 属性设置为 true 可启用飞出行为。有关更多信息,请参见演练:创建 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);
}

权限

另请参见

参考

MenuGroup 类

MenuGroup 成员

Microsoft.Windows.Design.Interaction 命名空间

MenuAction

PrimarySelectionContextMenuProvider

其他资源

演练:创建 MenuAction