King Lau - 博客园
source link: https://www.cnblogs.com/wfconquer/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
MOSS2007中的站点导航是基于ASP.NET的Navigation机制的,实际上在Masterpage中是可以任意定制页面中的导航控件的。在默认的TeamSite的Default.aspx中导航控件一共有三个.在MOSS中所有导航栏都是通过ASP:Menu控件或是ASP:TreeView控件绑定到一个NavigationDataSource实现的,因此每一个导航菜单都有两个控件共同实现。首先是一个ASP:Menu控件定义导航栏的样式和层级属性,其次是有一个 asp:SiteMapDataSource或SPNavigationProvider来作为导航栏的数据源。
打开Default.Mater可以发现,三个导航栏的实现各有不同,顶部的导航栏是通过一个SharePoint:DelegateControl动态加载asp:SiteMapDataSource作为数据源的,而左侧的两个则是通过SharePoint:DelegateControl动态加载一个SPNavigationProvider实现的数据源。
顶部的导航栏代码如下:
ID="TopNavigationMenu"
Runat="server"
DataSourceID="topSiteMap"
EnableViewState="false"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
Orientation="Horizontal"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="1"
DynamicHorizontalOffset="0"
StaticPopoutImageUrl="/_layouts/images/menudark.gif"
StaticPopoutImageTextFormatString=""
DynamicHoverStyle-BackColor="#CBE3F0"
SkipLinkText=""
StaticSubMenuIndent="0"
CssClass="ms-topNavContainer">
<StaticMenuStyle/>
<StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
<StaticSelectedStyle CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
<DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE" BorderWidth="1px"/>
<DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
<DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
<DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
</SharePoint:AspMenu>
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource">
<Template_Controls>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="SPNavigationProvider"
id="topSiteMap"
runat="server"
StartingNodeUrl="sid:1002"/>
</Template_Controls>
</SharePoint:DelegateControl>
其中aspmenu的使用没什么难度,用户可以自定义CSS样式和定义一些显示的级次。这里插入一个SharePoint CssRegistration控件的用法,就是自定义CSS文件,前面有一篇文章我曾经专门讲过如何自定义CSS文件,这里介绍一个CssRegistration的用法,在SharePoint页面的Head中加入:
其中,name为该CSS文件的地址。
值得一提的是下面的DelegateControl控件动态加载了一个SiteMapDataSource,其中SiteMapProvider="SPNavigationProvider"才是真正的指定数据源,而后面的StartingNodeUrl="sid:1002"则定义了该站点导航栏的起始位置,注意左侧的导航栏的起始位置和顶部的就不一样。因为顶部的导航栏通常都是从SiteCollection开始的,而左侧的导航栏是从当前站点开始的。ok,就是说可以通过更改顶部导航栏的MaximumDynamicDisplayLevels来让顶部导航栏显示更多的级次,从而显示站点中定义的List , Document Libraries等。
开发人员可以通过定义一个XMLDataSource,然后将ASPMenu的DataSourceID指向XMLDataSource的ID来实现自定义的导航栏。例如写一个XMLDataSource 如下。
BackColor="#F1F1F1" DynamicHorizontalOffset="2" Font-Names="Verdana" ForeColor="#990000"
StaticSubMenuIndent="0" Orientation="Vertical" StaticDisplayLevels="2" ItemWrap="true"
MaximumDynamicDisplayLevels="0">
<DataBindings>
<asp:MenuItemBinding DataMember="siteMapNode" NavigateUrlField="url"
TextField="title" ToolTipField="description" ValueField="title" />
</DataBindings>
</asp:Menu>
<asp:XmlDataSource DataFile="sitemap.xml" ID="DemoXmlDataSource" runat="server" XPath="/*/*"></asp:XmlDataSource>
其中sitemap.xml文件如下。
<siteMap xmlns="http://demo/testsite/SiteMap" >
<siteMapNode title="CustomMenu" url="CustomMenu.aspx" description="Go To Custom Menu">
<siteMapNode title="Menu Link 1" url="MenuLink1.aspx" description="Go To Menu Link 1" />
<siteMapNode title="Menu Link 2" url="MenuLink2.aspx" description="Go To Menu Link 2" />
</siteMapNode>
</siteMap>
同样开发人员可以在代码中控制导航栏控件,下面的代码DEMO了使用C#修改并添加了一个导航栏控件(其中SiteDemo为一个SPWeb对象)。
SPNavigationNode navDemoNode = new SPNavigationNode("Custom Menu", "#", false);
nodesDemo.AddAsFirst(navDemoNode);
SPNavigationNode subnavDemoNode1 = new SPNavigationNode("Menu Item 1", "http://demo:8001/", true);
nodesDemo[0].Children.AddAsFirst(subnavDemoNode1);
SPNavigationNode subnavDemoNode2 = new SPNavigationNode("Menu Item 2", "http://demo:8002", true);
nodesDemo[0].Children.AddAsFirst(subnavDemoNode2);
siteDemo.Update();
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK