MenuItem.Depth 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
메뉴 항목이 표시되는 수준을 가져옵니다.
public:
property int Depth { int get(); };
[System.ComponentModel.Browsable(false)]
public int Depth { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Depth : int
Public ReadOnly Property Depth As Integer
속성 값
메뉴 항목이 표시되는 수준입니다.
- 특성
예제
다음 예제에서는 메뉴 항목의 깊이를 확인 하는 속성을 사용 Depth 하는 방법을 보여 줍니다.
<%@ 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)
{
// If the Menu control contains any root nodes, perform a
// preorder traversal of the tree and display the text of
// nodes with a depth of 2.
if (NavigationMenu.Items.Count > 0)
{
// Iterate through the root menu items in the Items collection.
foreach (MenuItem item in NavigationMenu.Items)
{
DisplayChildMenuText(item);
}
}
else
{
Message.Text = "The Menu control does not have any items.";
}
}
void DisplayChildMenuText(MenuItem item)
{
// Use the Depth property to determine the depth of a
// menu item. Display only items with a depth of 2.
if (item.Depth == 2)
{
Message.Text += item.Text + "<br />";
}
// Iterate through the child menu items of the parent menu item
// passed into this method, and display their values.
foreach (MenuItem childItem in item.ChildItems)
{
// Recursively call the DisplayChildMenuText method to
// traverse the tree.
DisplayChildMenuText(childItem);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItem Depth Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItem Depth Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
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/>
Menu items with a depth of 2:<br/><br/>
<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)
' If the Menu control contains any root menu items, perform a
' preorder traversal of the tree and display the text of
' menu items with a depth of 2.
If NavigationMenu.Items.Count > 0 Then
' Iterate through the root menu items in the Items collection.
Dim item As MenuItem
For Each item In NavigationMenu.Items
DisplayChildMenuText(item)
Next
Else
Message.Text = "The Menu control does not have any items."
End If
End Sub
Sub DisplayChildMenuText(ByVal item As MenuItem)
' Use the Depth property to determine the depth of a
' menu item. Display only items with a depth of 2.
If item.Depth = 2 Then
Message.Text += item.Text + "<br />"
End If
' Iterate through the child menu items of the parent menu item
' passed into this method, and display their values.
Dim childItem As MenuItem
For Each childItem In item.ChildItems
' Recursively call the DisplayChildMenuText method to
' traverse the tree.
DisplayChildMenuText(childItem)
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItem Depth Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItem Depth Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
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/>
Menu items with a depth of 2:<br/><br/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
설명
Depth 이 속성을 사용하여 메뉴 항목의 깊이를 확인합니다. 깊이는 메뉴 항목이 표시되는 수준을 나타내며 현재 메뉴 항목과 루트 메뉴 항목 간의 계층 수준 수를 나타냅니다. 예를 들어 루트 메뉴 항목의 깊이는 0입니다. 루트 메뉴 항목의 하위 메뉴 항목의 깊이는 1 등입니다.