适用于: SharePoint 2016 |SharePoint Foundation 2013 |SharePoint Online |SharePoint Server 2013
定义下压按钮控件。
<Button
     Alt="Text"
     Command="Text"
     CommandType="General | OptionSelect | IgnoredByMenu"
     CommandValueId="Text"
     Description="Text"
     Id="Text"
     Image32by32="Url"
     Image32by32Class="CSS Class Selector"
     Image32by32Left="Negative Integer"
     Image32by32Top="Negative Integer"
     Image16by16="Url"
     Image16by16Class="CSS Class Selector"
     Image16by16Left="Negative Integer"
     Image16by16Top="Negative Integer"
     LabelCss="Text"
     LabelText="Text"
     MenuItemId="Text"
     Sequence="Integer"
     TemplateAlias="Text"
     ToolTipImage32by32="Url"
     ToolTipImage32by32Class="Text"
     ToolTipImage32by32Left="Negative Integer"
     ToolTipImage32by32Top="Negative Integer"
     ToolTipTitle="Text"
     ToolTipDescription="Text"
     ToolTipHelpKeyWord="Text"
     ToolTipShortcutKey="Text"
/>
元素和属性
下面各部分介绍了属性、子元素和父元素。
Attributes
| 属性 | 说明 | 
|---|---|
| Alt | 可选。 按钮的可选文本。 | 
| 命令 | 可选。 选择控件时要执行的命令的名称。 如果此控件在 CommandUIDefinition 元素中,则此控件的 Command 属性值应该与相应 CommandUIHandler 元素的 Command 属性值相同。 | 
| CommandType | 可选。 指定命令类型的枚举值。 常规。 不是特定类型的命令。 OptionSelection。 用户选择选项组中的某个选项时生成的命令。 IgnoredByMenu。 一个命令,用于在选定时不应关闭菜单的控件。 | 
| CommandValueId | 可选。 在选择按钮时随命令事件一起发送的字符串。 | 
| 说明 | 可选。 描述按钮的字符串。 仅当按钮位于某个菜单中并且使用 Menu32 显示模式呈现时,才会显示该说明。 | 
| Id | 必填。 用于标识控件的字符串,例如“Ribbon.Library.Share.NewRibbonButton”。 | 
| Image32by32 | 可选。 包含要用作图标的 32 x 32 像素图像的文件相对于服务器的 URL,例如“/_layouts/1033/images/formatmap32x32.png”。 | 
| Image32by32Class | 可选。 应用于图像的 CSS 类选择器的名称。 | 
| Image32by32Left | 可选。 一个负整数,表示图像左边缘的偏移。 当 Image32by32 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。 Image32by32Left 属性的值用于设置级联样式 HTML img 标记的 CSS left 属性。 例如,将 Image32by32Left 属性设置为“-160”, 将 Image32by32Top 属性设置为“-448”,将生成类似于以下 HTML 标记中的内联样式: HTML<img src="/_layouts/1033/images/formatmap32x32.png" style="position: absolute;left: -160px;top: -448px;" /> | 
| Image32by32Top | 可选。 一个负整数,表示图像上边缘的偏移。 当 Image32by32 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。 Image32by32Top 属性的值用于设置级联样式 HTML img 标记的 CSS top 属性。 | 
| Image16by16 | 可选。 包含要用作图标的 16 x 16 像素图像的文件的相对于服务器的 URL,例如“/_layouts/1033/images/formatmap16x16.png”。 | 
| Image16by16Class | 可选。 应用于图像的 CSS 类选择器的名称。 | 
| Image16by16Left | 可选。 一个负整数,表示图像左边缘的偏移。 当 Image16by16 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。 Image16by16Left 属性的值用于设置级联样式 HTML img 标记的 CSS left 属性。 | 
| Image16by16Top | 可选。 一个负整数,表示图像上边缘的偏移。 当 Image16by16 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。 Image16by16Top 属性的值用于设置级联样式 HTML img 标记的 CSS top 属性。 | 
| LabelCs | 可选。 应用于控件标签的 CSS 类选择器的名称。 | 
| LabelText | 可选。 用于标注控件的文本。 | 
| MenuItemId | 可选。 用于标识按钮所在的菜单项的字符串。 | 
| Sequence | 可选。 一个指定同级 XML 节点之间的放置顺序的整数。 | 
| TemplateAlias | 可选。 一个匹配 ControlRef 元素、OverflowArea 元素或 GroupTemplate 元素中的 OverflowSection 元素的 TemplateAlias 属性值的字符串。 在对某个组应用模板时,可使用 TemplateAlias 属性调整该组中控件的大小和位置。 | 
| ToolTipImage32by32 | 可选。 文件的相对于服务器的 URL,该文件包含要用于工具提示的 32 x 32 像素图像,例如“/_layouts/1033/images/formatmap32x32.png”。 | 
| ToolTipImage32by32Class | 可选。 应用于图像的 CSS 类选择器的名称。 | 
| ToolTipImage32by32Left | 可选。 一个负整数,表示图像左边缘的偏移。 当 ToolTipImage32by32 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。 ToolTipImage32by32Left 属性的值可用于在创建页面时设置 CSS left 属性。 | 
| ToolTipImage32by32Top | 可选。 一个负整数,表示图像上边缘的偏移。 当 ToolTipImage32by32 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。 ToolTipImage32by32Top 属性的值可用于在创建页面时设置 CSS top 属性。 | 
| ToolTipTitle | 可选。 显示为工具提示标题的文本。 | 
| ToolTipDescription | 可选。 显示在工具提示正文中的文本。 | 
| ToolTipHelpKeyWord | 可选。 上下文相关帮助使用的关键字。 | 
| ToolTipShortcutKey | 可选。 在工具提示中针对快捷键显示的文本。 例如,如果控件的快捷键为 Alt+J,则此属性的值为“Alt+J”。 工具提示将在工具提示标题后面的括号中显示快捷键的文本:“ (Alt+J) ”。 | 
子元素
无
父元素
- CommandUIDefinition
- Controls (Group)
- Controls (MenuSection)
出现次数
- 最小值:0
- 最大值:无限制
示例
以下示例演示如何将按钮控件添加到服务器功能区。 该示例将“帮助”按钮添加到与内置“新建文档”、“新建文件夹”和“上传文档”控件相同的组中的功能区:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="NewUIRibbonControl"
    RegistrationType="List"
    RegistrationId="101"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
           Location="Ribbon.Documents.New.Controls._children">
          <Button
             Id="NewUIRibbonControl.ShowHelp"
             Alt="Help"
             Sequence="1981"
             Command="ShowHelp"
             Image32by32="/_layouts/images/newui/dochelp.png"
             LabelText="Help"
             TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="ShowHelp"
         CommandAction="javascript:window.open('https://msdn.microsoft.com/library/ee539395%28office.14%29.aspx');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>