Button 元素

上次修改时间: 2015年3月9日

适用范围: SharePoint Foundation 2010

本文内容
属性
子元素
父元素
出现次数

定义下压按钮控件。

<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"
/>

属性

属性

说明

Alt

可选。按钮的可选文本。

Command

可选。单击控件时要执行的命令的名称。如果此控件在 CommandUIDefinition 元素中,则此控件的 Command 属性值应该与相应 CommandUIHandler 元素的 Command 属性值相同。

CommandType

可选。指定命令类型的枚举值。

  • General。不是特定类型的命令。

  • OptionSelection。用户选择选项组中的某个选项时生成的命令。

  • IgnoredByMenu。用于控件的命令,在单击这些控件时不应关闭菜单。

CommandValueId

可选。在单击按钮时随命令事件一起发送的字符串。

Description

可选。描述按钮的字符串。仅当按钮位于某个菜单中并且使用 Menu32 显示模式呈现时,才会显示该说明。

Id

必需。用于标识控件的字符串,例如"Ribbon.Library.Share.NewRibbonButton"。

Image32by32

可选。文件相对于服务器的 URL,该文件包含要用作图标的 32 X 32 像素图像,例如"/_layouts/1033/images/formatmap32x32.png"。

Image32by32Class

可选。应用于图像的 CSS 类选择器的名称。

Image32by32Left

可选。一个负整数,表示图像左边缘的偏移。当 Image32by32 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。

Image32by32Left 属性的值用于设置级联样式 HTML img 标记的 CSS left 属性。例如,将 Image32by32Left 属性设置为"-160",将 Image32by32Top 属性设置为"-448"将会生成与以下 HTML 标记中类似的级联样式:

<img src="/_layouts/1033/images/formatmap32x32.png" style="position: absolute;left: -160px;top: -448px;" />

Image32by32Top

可选。一个负整数,表示图像上边缘的偏移。当 Image32by32 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。Image32by32Top 属性的值用于设置级联样式 HTML img 标记的 CSS top 属性。

Image16by16

可选。文件相对于服务器的 URL,该文件包含要用作图标的 16 X 16 像素图像,例如"/_layouts/1033/images/formatmap16x16.png"。

Image16by16Class

可选。应用于图像的 CSS 类选择器的名称。

Image16by16Left

可选。一个负整数,表示图像左边缘的偏移。当 Image16by16 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。Image16by16Left 属性的值用于设置级联样式 HTML img 标记的 CSS left 属性。

Image16by16Top

可选。一个负整数,表示图像上边缘的偏移。当 Image16by16 属性指向一个图像文件(其中包含许多图标的图像)时,使用此属性。Image16by16Top 属性的值用于设置级联样式 HTML img 标记的 CSS top 属性。

LabelCss

可选。应用于控件标签的 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

最大值:无限制

示例

以下示例演示如何向服务器功能区添加按钮控件。该示例向功能区上添加一个"Help"按钮,并使其与内置的"新建文档"、"新建文件夹"和"上载文档"控件位于同一组中:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="https://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/en-us/library/ee539395%28office.14%29.aspx');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

请参阅

任务

演练:向服务器功能区中添加按钮