设为首页 收藏本站
查看: 958|回复: 0

[经验分享] Sharepoint学习笔记—Ribbon系列-- 4. 在Ribbon中添加新Group(针对用户自定义Tab)

[复制链接]

尚未签到

发表于 2015-9-24 10:20:11 | 显示全部楼层 |阅读模式
  知道如何取得正确的Location,我们就可以来进一步操作我们的自定义Ribbon对象了。这里,我们将偿试向我们在前面创建的My Custom Tab中添加一个新的Group: Custom Img Group,这个Group位于已有的Group(Custom Group)之后。
DSC0000.jpg
  下面 直接进入操作步骤   
  一、创建 SharePoint 项目
  要添加新选项卡,应首先创建一个空白 SharePoint 项目。如下:
    DSC0001.jpg
  把此方案设置成Farm解决方案

    然后在此项目中分别加入新的Feature与新的空白Element如下图
DSC0002.jpg

   
  

   二、使用自定义操作中的功能区 XML 定义功能区自定义项
    方法是 打开 CustomRibbonGroupEelement下的Elements.xml 文件,其内容如下:   
  


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
      Id="Ribbon.CustomTabExample.CutomImgGroup"
      Location="CommandUI.Ribbon"
      RegistrationId="101"
      RegistrationType="List">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition
                  Location="Ribbon.CustomTabExample.Groups._children">
                    <Group
                      Id="Ribbon.CustomTabExample.CutomImgGroup"
                      Sequence="62"
                      Description="Custom Img Group"
                      Title="Custom Img Group"
                      Command="CustomTabExample.EnableCustomGroup"
                      Template="Ribbon.Templates.CustomTemplateExampleImg">
                        <Controls Id="Ribbon.CustomTabExample.CutomImgGroup.Controls" >
                            <Button
                              Id="Ribbon.CustomTabExample.CutomImgGroup.CustomImgGroupHello"
                              Command="CustomTabExample.CustomImgGroupHelloWorld"
                              LabelText="Hello,Img Group World"
                              Description="Says Hello,Img World!"
                              TemplateAlias="cust5"
                              Sequence="25" />
                            <Button
                              Id="Ribbon.CustomTabExample.CutomImgGroup.CustomImgGroupGoodbye"
                              Command="CustomTabExample.CustomImgGroupGoodbyeWorld"
                               LabelText="Good-bye, Img Group World"
                               Description="SaysGood-bye, Img World!"
                              TemplateAlias="cust6"
                              Sequence="35" />
                        </Controls>
                    </Group>
                </CommandUIDefinition>
                <CommandUIDefinition  Location="Ribbon.CustomTabExample.Scaling._children">
                    <MaxSize
                      Id="Ribbon.CustomTabExample.Scaling.CutomImgGroup.MaxSize"
                      Sequence="15"
                      GroupId="Ribbon.CustomTabExample.CutomImgGroup"
                      Size="OneLargeTwoMediumImg" />
                </CommandUIDefinition>
                <CommandUIDefinition Location="Ribbon.Templates._children">
                    <GroupTemplate Id="Ribbon.Templates.CustomTemplateExampleImg">
                        <Layout
                          Title="OneLargeTwoMediumImg"
                          LayoutTitle="OneLargeTwoMediumImg">
                            <Section Alignment="Top" Type="OneRow">
                                <Row>
                                    <ControlRef DisplayMode="Large" TemplateAlias="cust4" />
                                </Row>
                            </Section>
                            <Section Alignment="Top" Type="TwoRow">
                                <Row>
                                    <ControlRef DisplayMode="Medium" TemplateAlias="cust5" />
                                </Row>
                                <Row>
                                    <ControlRef DisplayMode="Medium" TemplateAlias="cust6" />
                                </Row>
                            </Section>
                        </Layout>
                    </GroupTemplate>
                </CommandUIDefinition>
            </CommandUIDefinitions>
            <CommandUIHandlers>
                <CommandUIHandler  Command="CustomTabExample.EnableCustomGroup"
                                   CommandAction="javascript:return true;" />
                <CommandUIHandler
                  Command="CustomTabExample.CustomImgGroupHelloWorld"
                  CommandAction="javascript:alert('Hello, Imag Group world!');" />
                <CommandUIHandler
                  Command="CustomTabExample.CustomImgGroupGoodbyeWorld"
                  CommandAction="javascript:alert('Good-bye, Img Group world!');" />
            </CommandUIHandlers>
        </CommandUIExtension>
    </CustomAction>
</Elements>  
  下面对其内容作如下说明:  
   首先我们要用上一篇介绍的确定Location的方法找到我们需要添加的Group应该添加在Ribbon的哪个位置。
  本例我们确定的位置就是Ribbon.CustomTabExample  (格式是: [Ribbon].[Tab].[你要添加的Group的名字]),我们把它命名为CutomImgGroup,所以此新的Group的ID就成了Ribbon.CustomTabExample.CutomImgGroup。如下面代码


<CustomAction
      Id="Ribbon.CustomTabExample.CutomImgGroup"
      Location="CommandUI.Ribbon"
      RegistrationId="101"
      RegistrationType="List">
        <CommandUIExtension>
            <CommandUIDefinitions>
                <CommandUIDefinition
                  Location="Ribbon.CustomTabExample.Groups._children">
                    <Group  从面上的代码我们还应该知道,由于我们确定的位置是Ribbon.CustomTabExample这个Tab ,我们要在这个Tab下添加新的Group,而这个新增的Group是这个Tab的Groups中的一个成员,所以,对于这个新增Group的正确的Location表达格式是:[Ribbon].[目标Tab].Groups._children。这样,我们就可以把我们新增的Group添加到正确的位置。
  但这样还不够,我们还需要正确的显示它,对于Ribbon元素的显示,需要注意的一是显示时机,二是显示方式。
  对于显示时机,可以从上面的RegistrationID与RegistrationType等等属性的设置来影响,这里的设置当然要与已经存在的用户自定义的Tab的设置保持一致,如果不同步就不会看到你新增的Group,即使它存在的位置就在这个Tab中。


                  <Group
                      Id="Ribbon.CustomTabExample.CutomImgGroup"
                      Sequence="62"
                      Description="Custom Img Group"
                      Title="Custom Img Group"
                      Command="EnableCustomImgGroup"
                      Template="Ribbon.Templates.CustomTemplateExampleImg">
                        <Controls Id="Ribbon.CustomTabExample.CutomImgGroup.Controls" >  
  接下来我们定义了需要添加的Group,这里需要注意的是Template属性,我们知道,Sharepoint Ribbon的任何Group都必须与某个GroupTemplate进行绑定,我们这里针对新添加的Group需要创建一个新的GroupTemplate: Ribbon.Templates.CustomTemplateExampleImg并将它与我们新增的Group进行绑定。下面就是我们创建的新的GroupTemplate代码


                 <CommandUIDefinition Location="Ribbon.Templates._children">
                    <GroupTemplate Id="Ribbon.Templates.CustomTemplateExampleImg">
                        <Layout
                          Title="OneLargeTwoMediumImg"
                          LayoutTitle="OneLargeTwoMediumImg">
                            <Section Alignment="Top" Type="OneRow">
                                <Row>
                                    <ControlRef DisplayMode="Large" TemplateAlias="cust4" />
                                </Row>
                            </Section>
                            <Section Alignment="Top" Type="TwoRow">
                                <Row>
                                    <ControlRef DisplayMode="Medium" TemplateAlias="cust5" />
                                </Row>
                                <Row>
                                    <ControlRef DisplayMode="Medium" TemplateAlias="cust6" />
                                </Row>
                            </Section>
                        </Layout>
                    </GroupTemplate>
                </CommandUIDefinition>  上面的代码需要注意的是 Location: Location="Ribbon.Templates._children",这是GroupTemplate存在的位置。我们新增的Group将会到此位置去找它引用的GroupTemplate。
  创建并 设置了Group引用的GroupTemplate,我们还需要把Group内的Controls与这个Template的相关设置关联起来,代码如下:
  


                       <Controls Id="Ribbon.CustomTabExample.CutomImgGroup.Controls" >
                            <Button
                              Id="Ribbon.CustomTabExample.CutomImgGroup.CustomImgGroupHello"
                              Command="CustomTabExample.CustomImgGroupHelloWorld"
                              LabelText="Hello,Img Group World"
                              Description="Says Hello,Img World!"
                              TemplateAlias="cust5"
                              Sequence="25" />
                            <Button
                              Id="Ribbon.CustomTabExample.CutomImgGroup.CustomImgGroupGoodbye"
                              Command="CustomTabExample.CustomImgGroupGoodbyeWorld"
                               LabelText="Good-bye, Img Group World"
                               Description="SaysGood-bye, Img World!"
                              TemplateAlias="cust6"
                              Sequence="35" />
                        </Controls>  从代码中可以看到,我们创建了两个Button,它们通过TemplateAlias与GroupTemplate中设置的Section内容相关联。
  如果此时你部署了你的NewGroup,你会发现你可以看到它出现在了正确的位置,但你看不到你在其中创建的Controls。这是因为我们还没有创建针对这个Group的新的Scaling与MaxSize特性。所以你需要添加下面的代码


            <CommandUIDefinition  Location="Ribbon.CustomTabExample.Scaling._children">
                    <MaxSize
                      Id="Ribbon.CustomTabExample.Scaling.CutomImgGroup.MaxSize"
                      Sequence="15"
                      GroupId="Ribbon.CustomTabExample.CutomImgGroup"
                      Size="OneLargeTwoMediumImg" />
                </CommandUIDefinition>  此代码创建了一个新的Scaling设置,并通过Location="Ribbon.CustomTabExample.Scaling._children"确定了此Scaling属于Ribbon.CustomTabExample这个Tab的组成。然后又通过 GroupId="Ribbon.CustomTabExample.CutomImgGroup"把它与我们新创建的Group关联了起来。
  接下来的就是创建相关的Command项并与我们的Controls关联,这个就不用多说了。至此,我们就完成了新的用户自定义Group的创建与添加。
  
  三、部署自定义Group项
     按 F5。Visual Studio 2010 中的 SharePoint 开发工具将自动构建和部署功能。
     转到网站或子网站中的文档库。
    单击&#8220;My Custom Tab&#8221;选项卡,查看&#8220;自定义组&#8221;,然后单击&#8220;Hello, Img World&#8221;、&#8220;Good-bye, Img World&#8221;按钮。
DSC0003.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118084-1-1.html 上篇帖子: 博客园又添新书《深入体验Microsoft Office SharePoint Server实践开发》出版 下篇帖子: Sharepoint开发问题归纳(不断更新)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表