4

我发现了很多示例如何在功能区栏上添加带有自定义控件的自定义选项卡。但是没有人为我工作。我得到了自定义选项卡,但按钮总是被禁用。有我当前版本的代码:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="CustomRibbonTab"
    Location="CommandUI.Ribbon"
    RegistrationId="101"
    RegistrationType="List">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Tabs._children">
          <Tab
            Id="Ribbon.CustomTab"
            Title="Custom Tab"
            Description="Custom Tab !!!"
            Sequence="701">
            <Scaling
              Id="Ribbon.CustomTab.Scaling">
              <MaxSize
                Id="Ribbon.CustomTab.MaxSize"
                GroupId="Ribbon.CustomTab.CustomGroup"
                Size="OneLargeTwoMedium"/>
              <Scale
                Id="Ribbon.CustomTab.Scaling.CustomTabScaling"
                GroupId="Ribbon.CustomTab.CustomGroup"
                Size="OneLargeTwoMedium" />
            </Scaling>
            <Groups Id="Ribbon.CustomTab.Groups">
              <Group
                Id="Ribbon.CustomTab.CustomGroup"
                Description="Custom Group!"
                Title="Custom Group"
                Sequence="62"
                Template="Ribbon.Templates.CustomTemplate">
                <Controls Id="Ribbon.CustomTab.CustomGroup.Controls">
                  <Button
                    Id="Ribbon.CustomTab.CustomGroup.CustomButton"
                    Command="CustomTab.CustomButtonCommand"
                    Sequence="115"
                    Description=""
                    LabelText="Custom Button"
                    Image32by32="/_layouts/images/PPEOPLE.GIF"
                    TemplateAlias="cust1"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.CustomTemplate">
            <Layout
              Title="OneLargeTwoMedium"
              LayoutTitle="OneLargeTwoMedium">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust1" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="CustomTab.CustomButtonCommand"
           CommandAction="javascript:alert('Hello, world!');"
          EnabledScript="javascript:return true;"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

我清理了缓存。我在 CommandUIHandler 中了解了 EnabledScripts 属性的重要性。但我总是有相同的结果:

禁用按钮

有人有同样的问题吗?请帮忙!

4

2 回答 2

3

我有同样的问题,我不确定这是否是正确的解决方案,我是新手。我从范围设置为“站点”的功能中删除了元素,添加了另一个功能,将范围设置为“Web”,在此功能中添加了我的按钮项,保存,部署,从站点功能启用新功能并且它工作。

于 2014-08-07T12:46:43.700 回答
3

我检查了我的一个本地自定义操作,而 EnabledScript 遵循了不同的模式:

EnabledScript="javascript:function JustReturnTrue()
{
      return true
}
JustReturnTrue();" 

如果您的项目出现了,但总是被禁用,我敢打赌这就是问题所在。

如果我记得的话,我认为该属性无论如何都是可选的。

于 2013-09-09T23:42:38.640 回答