菜单组

菜单组在菜单或工具栏中组织相关的命令和控件。

简介

通过 MenuGroup 标记元素公开的 “菜单组 ”控件是基于菜单的控件(包括 上下文弹出 式浮动工具栏)中的项或命令组的逻辑容器。

可以通过关联 Command 声明的 LabelTitle 属性或 Command.LabelTitle 属性为菜单组指定标签。 分配给 LabelTitle 的值呈现为类别标头。

以下示例演示包含两个菜单组命令声明的 拆分按钮 控件的命令标记。

<!-- SplitButton -->
<Command Name="cmdSplitButtonGroup"
         Symbol="cmdSplitButtonGroup"
         Comment="SplitButton Group"
         LabelTitle="SplitButton"/>
<Command Name="cmdSplitButton"
         Symbol="cmdSplitButton"
         Comment="SplitButton"
         LabelTitle="SplitButton"/>
<Command Name="cmdSBButtonItem"
         Symbol="cmdSBButtonItem"
         Comment="SBButtonItem"
         LabelTitle="SB ButtonItem"/>
<Command Name="cmdSBButton1"
         Symbol="cmdSBButton1"
         Comment="SBButton1"
         LabelTitle="SB Button">
  <Command.LargeImages>
    <Image Source="res/copyL_32.bmp"/>
  </Command.LargeImages>
  <Command.SmallImages>
    <Image Source="res/copyS_16.bmp"/>
  </Command.SmallImages>
  <Command.LargeHighContrastImages>
    <Image Source="res/copyLHC_32.bmp"/>
  </Command.LargeHighContrastImages>
  <Command.SmallHighContrastImages>
    <Image Source="res/copySHC_16.bmp"/>
  </Command.SmallHighContrastImages>
</Command>
<Command Name="cmdSBMajorItems"
         Comment="Major Items Category"
         LabelTitle="Major Items"/>
<Command Name="cmdSBStandardItems"
         Comment="Standard Items Category"
         LabelTitle="Standard Items"/>

以下示例演示具有三个 MenuGroup 元素声明的 SplitButton 元素所需的标记,其中两个声明与上一示例中的菜单组命令相关联。 MenuGroup 元素的 Class 属性用于指定菜单项的大小。

<Group CommandName="cmdSplitButtonGroup">
  <SplitButton CommandName="cmdSplitButton">
    <SplitButton.ButtonItem>
      <Button CommandName="cmdSBButtonItem"/>
    </SplitButton.ButtonItem>
    <SplitButton.MenuGroups>
      <MenuGroup CommandName="cmdSBMajorItems" 
                 Class="MajorItems">
        <Button CommandName="cmdSBButton1"/>
        <Button CommandName="cmdSBButton1"/>
      </MenuGroup>
      <MenuGroup CommandName="cmdSBStandardItems"
                 Class="StandardItems">
        <Button CommandName="cmdSBButton1"/>
        <Button CommandName="cmdSBButton1"/>
      </MenuGroup>
      <MenuGroup Class="StandardItems">
        <Button CommandName="cmdSBButton1"/>
        <Button CommandName="cmdSBButton1"/>
      </MenuGroup>
    </SplitButton.MenuGroups>
  </SplitButton>
</Group>

以下屏幕截图演示了菜单 (,其中包含三个菜单组控件) ,这些控件是从前面示例中的标记生成的。

具有三个菜单组控件的菜单的屏幕截图。

功能区框架定义菜单组控件 的属性键 集合。

通常,通过调用 IUIFramework::InvalidateUICommand 方法使与控件关联的命令失效,从而在功能区 UI 中更新菜单组属性。 无效事件由 IUICommandHandler::UpdateProperty 回调方法处理,并更新定义的属性。

IUICommandHandler::UpdateProperty 回调方法不会执行,应用程序会查询更新的属性值,直到框架需要该属性。 例如,在功能区 UI 中激活选项卡和显示控件时,或显示工具提示时。

注意

在某些情况下,可以通过 IUIFramework::GetUICommandProperty 方法检索属性,并使用 IUIFramework::SetUICommandProperty 方法进行设置。

 

下表列出了与菜单组控件关联的属性键。

属性键 说明
UI_PKEY_Enabled 支持 IUIFramework::GetUICommandPropertyIUIFramework::SetUICommandProperty
UI_PKEY_Keytip 只能通过失效进行更新。
UI_PKEY_Label 只能通过失效进行更新。
UI_PKEY_TooltipDescription 只能通过失效进行更新。
UI_PKEY_TooltipTitle 只能通过失效进行更新。

 

Windows 功能区框架控件库

MenuGroup 标记元素