SiteMapPath.InitializeItem(SiteMapNodeItem) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
根据节点功能和为节点指定的模板和样式,使用一组子控件填充 SiteMapNodeItem,这是一个表示 SiteMapNode 的 Web 服务器控件。
protected:
virtual void InitializeItem(System::Web::UI::WebControls::SiteMapNodeItem ^ item);
protected virtual void InitializeItem (System.Web.UI.WebControls.SiteMapNodeItem item);
abstract member InitializeItem : System.Web.UI.WebControls.SiteMapNodeItem -> unit
override this.InitializeItem : System.Web.UI.WebControls.SiteMapNodeItem -> unit
Protected Overridable Sub InitializeItem (item As SiteMapNodeItem)
参数
- item
- SiteMapNodeItem
要初始化的 SiteMapNodeItem。
示例
下面的代码示例演示如何重写 InitializeItem 方法,以向派生自 SiteMapPath的控件添加功能。 此代码示例是为类提供的大型示例的 SiteMapPath 一部分。
// Override the InitializeItem method to add a PathSeparator
// and DropDownList to the current node.
protected override void InitializeItem(SiteMapNodeItem item) {
// The only node that must be handled is the CurrentNode.
if (item.ItemType == SiteMapNodeItemType.Current)
{
HyperLink hLink = new HyperLink();
// No Theming for the HyperLink.
hLink.EnableTheming = false;
// Enable the link of the SiteMapPath is enabled.
hLink.Enabled = this.Enabled;
// Set the properties of the HyperLink to
// match those of the corresponding SiteMapNode.
hLink.NavigateUrl = item.SiteMapNode.Url;
hLink.Text = item.SiteMapNode.Title;
if (ShowToolTips) {
hLink.ToolTip = item.SiteMapNode.Description;
}
// Apply styles or templates to the HyperLink here.
// ...
// ...
// Add the item to the Controls collection.
item.Controls.Add(hLink);
AddDropDownListAfterCurrentNode(item);
}
else {
base.InitializeItem(item);
}
}
' Override the InitializeItem method to add a PathSeparator
' and DropDownList to the current node.
Protected Overrides Sub InitializeItem(item As SiteMapNodeItem)
' The only node that must be handled is the CurrentNode.
If item.ItemType = SiteMapNodeItemType.Current Then
Dim hLink As New HyperLink()
' No Theming for the HyperLink.
hLink.EnableTheming = False
' Enable the link of the SiteMapPath is enabled.
hLink.Enabled = Me.Enabled
' Set the properties of the HyperLink to
' match those of the corresponding SiteMapNode.
hLink.NavigateUrl = item.SiteMapNode.Url
hLink.Text = item.SiteMapNode.Title
If ShowToolTips Then
hLink.ToolTip = item.SiteMapNode.Description
End If
' Apply styles or templates to the HyperLink here.
' ...
' ...
' Add the item to the Controls collection.
item.Controls.Add(hLink)
AddDropDownListAfterCurrentNode(item)
Else
MyBase.InitializeItem(item)
End If
End Sub
注解
该方法 InitializeItem 通过检查 SiteMapNodeItemType项所表示的节点的功能类型,并应用为此类节点定义的任何模板或样式。
SiteMapNodeItem如果具有Root项类型,HyperLink则会创建子控件,并且可以RootNodeTemplate应用子RootNodeStyle控件。 RootNodeTemplate如果已设置,则将其ITemplate应用于节点。 RootNodeStyle相反,它将与任何已定义NodeStyle和应用合并。 最后,如果未定义模板或样式,则会创建一个基本 HyperLink 控件,并使用节点中的值进行初始化。
SiteMapNodeItem如果具有项类型,则创建一个CurrentLiteral或HyperLink子控件,具体取决于返回值RenderCurrentNodeAsLink。 然后,CurrentNodeTemplate可以应用或应用。CurrentNodeStyle CurrentNodeTemplate如果已设置,则将其ITemplate应用于节点。 如果已 CurrentNodeStyle 设置,则会将其与任何已定义 NodeStyle 和应用合并。
SiteMapNodeItem如果具有Parent项类型,HyperLink则会创建子控件并NodeTemplate应用子NodeStyle控件。 NodeTemplate如果已设置,则将其ITemplate应用于节点。 如果已 NodeStyle 设置,则应用该设置。
最后,如果SiteMapNodeItem具有PathSeparator项类型,Literal则会创建子控件,并根据PathSeparatorTemplatePathSeparatorStyle为Parent节点类型定义的相同常规规则应用子控件。
重写方法 InitializeItem 以操作单个 SiteMapNodeItem 对象。 如果类的设计需要对对象创建方式和添加到控件的方式SiteMapNodeItem进行更广泛的控制,请重写该方法CreateControlHierarchy。SiteMapPath