Menu.PathSeparator 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用于分隔 Menu 控件的菜单项路径的字符。
public:
property char PathSeparator { char get(); void set(char value); };
public char PathSeparator { get; set; }
member this.PathSeparator : char with get, set
Public Property PathSeparator As Char
属性值
用于分隔菜单项路径的字符。 默认值为斜杠 (/)。
示例
下面的代码示例演示如何使用 PathSeparator 属性将菜单项的值路径的分隔符字符更改为逗号。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// The value path for a menu item is a delimited list
// of menu text values that form a path from the root
// menu item to the current menu item.
// Declare the value path to the Classical menu item using
// the delimiter character specified in the PathSeparator
// property. In this example, the delimiter character is a
// comma.
String valuePath = "Home,Music,Classical";
// Use the FindItem method to get the Classical menu item using
// its value path.
MenuItem item = NavigationMenu.FindItem(valuePath);
// Indicate whether the menu item was found.
if (item != null)
{
Message.Text = item.Text + " menu item found at depth " +
item.Depth.ToString() + ".";
}
else
{
Message.Text = "Menu item not found.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu PathSeparator and FindItem Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu PathSeparator and FindItem Example</h3>
<!-- Use the PathSeparator property to -->
<!-- change the delimiter character for -->
<!-- the value path of a menu item to a -->
<!-- comma (,). -->
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
pathseparator=","
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' The value path for a menu item is a delimited list
' of menu text values that form a path from the root
' menu item to the current menu item.
' Declare the value path to the Classical menu item using
' the delimiter character specified in the PathSeparator
' property. In this example, the delimiter character is a
' comma.
Dim valuePath As String = "Home,Music,Classical"
' Use the FindItem method to get the Classical menu item using
' its value path.
Dim item As MenuItem = NavigationMenu.FindItem(valuePath)
' Indicate whether the menu item was found.
If Not item Is Nothing Then
Message.Text = item.Text & " menu item found at depth " & _
item.Depth.ToString() & "."
Else
Message.Text = "Menu item not found."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu PathSeparator and FindItem Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu PathSeparator and FindItem Example</h3>
<!-- Use the PathSeparator property to -->
<!-- change the delimiter character for -->
<!-- the value path of a menu item to a -->
<!-- comma (,). -->
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
pathseparator=","
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
注解
控件中Menu由对象 () 表示MenuItem的每个菜单项都有一个ValuePath指定菜单项位置的属性。 值路径是一个带分隔符的值字符串,它构成从根菜单项到当前菜单项的路径。 使用 PathSeparator 属性指定用于分隔菜单路径中的值的分隔符。 分析各个值的列表时,通常使用此值。
根据控件中显示的 Menu 文本,可能需要更改分隔符字符以防止任何冲突。 例如,如果将分隔符字符设置为逗号,则显示的文本不应包含任何逗号;否则, ValuePath 无法准确分析该属性。