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

[经验分享] Sharepoint自定义菜单栏

[复制链接]

尚未签到

发表于 2015-9-29 05:20:56 | 显示全部楼层 |阅读模式
  Sharepoint2010的UI有很大的改观,一个重要的体现是在Ribbon。然而有些人并不喜欢这种操作,所以我想到之前的2007的工具栏。
  在工具栏里面添加了新建,和删除项目,及切换视图。
  效果如下图:
DSC0000.png
  1:ToolBar
  需要先放置新建,删除项目按钮的容器。在Sharepoint里面有提供一个用户自定义控件,位置存放在C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES/ToolBar.ascx。因为想偷懒,这个控件都已经做好了样式,直接拿过来用就好了,当然也可以自己去修改样式。该ToolBar.ascx的代码如下:
<%@ Control Language=&quot;C#&quot; Inherits=&quot;Microsoft.SharePoint.WebControls.ToolBar,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c&quot;   AutoEventWireup=&quot;false&quot; compilationMode=&quot;Always&quot; %>
<%@ Register Tagprefix=&quot;wssawc&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %> <%@ Register Tagprefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<table class=&quot;<%=CssClass%>&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; id=&quot;<%=ClientID%>&quot; width=&quot;100%&quot;>
<tr>
<%-- Buttons on the left --%>
<wssawc:RepeatedControls id=&quot;RptControls&quot; runat=&quot;server&quot;>
<HeaderHtml/>
<BeforeControlHtml>
<td class=&quot;ms-toolbar&quot; nowrap=&quot;nowrap&quot;>
</BeforeControlHtml>
<AfterControlHtml>
</td>
</AfterControlHtml>
<SeparatorHtml>
<td class=&quot;ms-separator&quot;>|</td>
</SeparatorHtml>
<FooterHtml/>
</wssawc:RepeatedControls>
<td width=&quot;99%&quot; class=&quot;ms-toolbar&quot; nowrap=&quot;nowrap&quot;><img src=&quot;/_layouts/images/blank.gif&quot; width='1' height='18' alt=&quot;&quot; /></td>
<%-- Buttons on the right --%>
<wssawc:RepeatedControls id=&quot;RightRptControls&quot; runat=&quot;server&quot;>
<HeaderHtml/>
<BeforeControlHtml>
<td class=&quot;ms-toolbar&quot; nowrap=&quot;nowrap&quot;>
</BeforeControlHtml>
<AfterControlHtml>
</td>
</AfterControlHtml>
<SeparatorHtml>
<td class=&quot;ms-separator&quot;>|</td>
</SeparatorHtml>
<FooterHtml/>
</wssawc:RepeatedControls>
</tr>
</table>
  如果需要修改样式,建议在自己的样式表里面,重写这些定义的样式为好。
  我们引用这个工具栏控件:

<%@ Register Src=&quot;/_controltemplates/ToolBar.ascx&quot; TagPrefix=&quot;YLSoft&quot; TagName=&quot;ToolBar&quot; %>
  

<YLSoft:ToolBar ID=&quot;tbar&quot; runat=&quot;server&quot;>
<Template_Buttons>
</Template_Buttons>
<Template_RightButtons>
</Template_RightButtons>
</YLSoft:ToolBar>
  
  在Template_Buttons和Template_RightButtons分别放置左边,和最右边的按钮集合,一般我们视图选择都放在右边。里面直接拖拽控件也可以,为了美观,这里还是用到Sharepoint的几个控件 。
  Menu:

<SharePoint:Menu ID=&quot;MenuNew&quot; runat=&quot;server&quot; TemplateId=&quot;MenuTemplateNew&quot; Text=&quot;<%$Resources:wss,multipages_new_menu_text%>&quot;
MenuFormat=&quot;ArrowAlwaysVisible&quot; MenuAlignment=&quot;Left&quot; HoverCellActiveCssClass=&quot;ms-menubuttonactivehover&quot;
HoverCellInActiveCssClass=&quot;ms-menubuttoninactivehover&quot; AccessKey=&quot;<%$Resources:wss,tb_NewMenu_AK%>&quot; />
  这里有使用到资源文件,<%$Resources:wss,multipages_new_menu_text%>,意思是调用的是wss.resx,key为multipages_new_menu_text的资源。资源文件放在:目录下面。multipages_new_menu_text的值是New(新建)。

  <data name=&quot;multipages_new_menu_text&quot;>
<value>New</value>
</data>
  那这个MenuNew西面有哪些子菜单呢?这里有一个很重要的属性:TemplateId。TemplateId指明从哪个Template获取子菜单。这里我指明的是MenuTemplateNew。看看它的定义:

<SharePoint:FeatureMenuTemplate ID=&quot;MenuTemplateNew&quot; LargeIconMode=&quot;TRUE&quot; runat=&quot;server&quot; GroupId=&quot;NewMenu&quot;>
<SharePoint:NewMenu MenuAlignment=&quot;Default&quot; ID=&quot;newMenu&quot; runat=&quot;server&quot;>
</SharePoint:NewMenu>
</SharePoint:FeatureMenuTemplate>
  我在MenuTemplateNew的菜单模板下面放置了新增菜单。看看效果
DSC0001.png
  NewMenu都是取得当前列表的新增的内容类型。当然也可以自己编码来添加新增的内容。这貌似需要继承来实现。之前有重写过这个NewMenu。
  删除项目菜单:
  <YLSoft:ToolBarButton ID=&quot;btnDel&quot; OnClientClick=&quot;getSels();return false;&quot; runat=&quot;server&quot; Text=&quot;<%$Resources:wss,setanon_deleteitems_display %>&quot;></YLSoft:ToolBarButton>
  ToolBarButton样式都Sharepoint的,所以看上去顺眼点,如果直接放Button有点恶心。
  最后UI代码如下:

<%@ Assembly Name=&quot;$SharePoint.Project.AssemblyFullName$&quot; %>
<%@ Assembly Name=&quot;Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Register TagPrefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot;
Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Register TagPrefix=&quot;Utilities&quot; Namespace=&quot;Microsoft.SharePoint.Utilities&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Register TagPrefix=&quot;asp&quot; Namespace=&quot;System.Web.UI&quot; Assembly=&quot;System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; %>
<%@ Import Namespace=&quot;Microsoft.SharePoint&quot; %>
<%@ Register TagPrefix=&quot;WebPartPages&quot; Namespace=&quot;Microsoft.SharePoint.WebPartPages&quot;
Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Control Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;ListToolBarUserControl.ascx.cs&quot;
Inherits=&quot;YLSoft.Features.Webparts.ListToolBar.ListToolBarUserControl&quot; %>
<%@ Register Src=&quot;/_controltemplates/ToolBar.ascx&quot; TagPrefix=&quot;YLSoft&quot; TagName=&quot;ToolBar&quot; %>
<%@ Register TagPrefix=&quot;YLSoft&quot; TagName=&quot;ToolBarButton&quot; src=&quot;~/_controltemplates/ToolBarButton.ascx&quot; %>
<!-- Templates -->
<SharePoint:FeatureMenuTemplate ID=&quot;MenuTemplateNew&quot; LargeIconMode=&quot;TRUE&quot; runat=&quot;server&quot; GroupId=&quot;NewMenu&quot;>
<SharePoint:NewMenu MenuAlignment=&quot;Default&quot; ID=&quot;newMenu&quot; runat=&quot;server&quot;>
</SharePoint:NewMenu>
</SharePoint:FeatureMenuTemplate>
<SharePoint:MenuTemplate runat=&quot;server&quot; ID=&quot;MenuTemplateView&quot;>
<SharePoint:ViewSelectorMenu ID=&quot;viewSelector&quot; runat=&quot;server&quot;>
</SharePoint:ViewSelectorMenu>
</SharePoint:MenuTemplate>
<!--End Template-->
<YLSoft:ToolBar ID=&quot;tbar&quot; runat=&quot;server&quot;>
<Template_Buttons>
<SharePoint:Menu ID=&quot;MenuNew&quot; runat=&quot;server&quot; TemplateId=&quot;MenuTemplateNew&quot; Text=&quot;<%$Resources:wss,multipages_new_menu_text%>&quot;
MenuFormat=&quot;ArrowAlwaysVisible&quot; MenuAlignment=&quot;Left&quot; HoverCellActiveCssClass=&quot;ms-menubuttonactivehover&quot;
HoverCellInActiveCssClass=&quot;ms-menubuttoninactivehover&quot; AccessKey=&quot;<%$Resources:wss,tb_NewMenu_AK%>&quot; />
<YLSoft:ToolBarButton ID=&quot;btnDel&quot; OnClientClick=&quot;getSels();return false;&quot; runat=&quot;server&quot; Text=&quot;<%$Resources:wss,setanon_deleteitems_display %>&quot;></YLSoft:ToolBarButton>
</Template_Buttons>
<Template_RightButtons>
<asp:PlaceHolder ID=&quot;PlaceHolder1&quot; runat=&quot;server&quot;>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style='margin-right: 4px'>
<tr>
<td nowrap=&quot;nowrap&quot; class=&quot;ms-toolbar&quot; id=&quot;topPagingCell&quot;></td>
<td></td>
<td nowrap=&quot;nowrap&quot;>&#160;</td>
<td nowrap=&quot;nowrap&quot; class=&quot;ms-listheaderlabel&quot;><SharePoint:EncodedLiteral ID=&quot;EncodedLiteral1&quot; runat=&quot;server&quot; text=&quot;<%$Resources:wss,view_selector_view%>&quot; EncodeMethod='HtmlEncode'/>&#160;</td>
<td nowrap=&quot;nowrap&quot; class=&quot;ms-viewselector&quot; onmouseover=&quot;this.className='ms-viewselectorhover'&quot; onmouseout=&quot;this.className='ms-viewselector'&quot; id=&quot;onetPeopleViewSelector&quot;>
<SharePoint:Menu ID=&quot;MenuViewSelector&quot; runat=&quot;server&quot; TemplateId=&quot;MenuTemplateView&quot;
Text=&quot;<%$Resources:wss,mngsubwebs_selectview%>&quot; MenuFormat=&quot;ArrowAlwaysVisible&quot;
MenuAlignment=&quot;Right&quot; AlignmentElementOverrideClientId=&quot;onetPeopleViewSelector&quot;
HoverCellActiveCssClass=&quot;ms-viewselectorhover&quot; HoverCellInActiveCssClass=&quot;ms-viewselector&quot;
AccessKey=&quot;<%$Resources:wss,tb_ViewSelector_AK%>&quot; />
</td>
</tr>
</table>
</asp:PlaceHolder>
</Template_RightButtons>
</YLSoft:ToolBar>

运维网声明 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-120111-1-1.html 上篇帖子: SharePoint 2010 部署 WSP 包 下篇帖子: Windows SharePoint Service 3.0自定义列表字段的接口
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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