MenuItemBinding.Depth プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
MenuItemBinding オブジェクトが適用されるメニューの深さを取得または設定します。
public:
property int Depth { int get(); void set(int value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Depth : int with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Depth : int with get, set
Public Property Depth As Integer
プロパティ値
MenuItemBindingが適用されるメニューの深さ。 既定値は -1 で、このプロパティが設定されていないことを示します。
- 属性
例
次のコード例では、 Depth プロパティを使用して、 MenuItemBinding オブジェクトを適用するメニューの深さを指定する方法を示します。 この例を正しく機能させるには、以下のサンプル XML データを MenuDepth.xmlという名前のファイルにコピーする必要があります。
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBinding Depth Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBinding Depth Example</h3>
<asp:menu id="NavigationMenu"
datasourceid="MenuSource"
runat="server">
<databindings>
<asp:menuitembinding depth="0"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"
target="_self" />
<asp:menuitembinding depth="1"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"
target="_blank"/>
<asp:menuitembinding depth="2"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"
target="_blank"/>
</databindings>
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="MenuDepth.xml"
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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBinding Depth Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBinding Depth Example</h3>
<asp:menu id="NavigationMenu"
datasourceid="MenuSource"
runat="server">
<databindings>
<asp:menuitembinding depth="0"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"
target="_self" />
<asp:menuitembinding depth="1"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"
target="_blank"/>
<asp:menuitembinding depth="2"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"
target="_blank"/>
</databindings>
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="MenuDepth.xml"
runat="server"/>
</form>
</body>
</html>
次のコードは、前の例のサンプル サイト マップ データです。
<MapNode ImageUrl="~\Images\Home.gif"
Title="Home"
Description="Root Page"
ToolTip="Home Page">
<MapNode ImageUrl="~\Images\Music.gif"
Title="Music"
Description="Music Category"
ToolTip="Music Page">
<MapNode ImageUrl="~\Images\Classical.gif"
Title="Classical"
Description="Classical Section"
ToolTip="Classical Page"/>
<MapNode ImageUrl="~\Images\Rock.gif"
Title="Rock"
Description="Rock Section"
ToolTip="Rock Page"/>
<MapNode ImageUrl="~\Images\Jazz.gif"
Title="Jazz"
Description="Jazz Section"
ToolTip="Jazz Page"/>
</MapNode>
<MapNode ImageUrl="~\Images\Movies.gif"
Title="Movies"
Description="Movies Category"
ToolTip="Movies Page">
<MapNode ImageUrl="~\Images\Action.gif"
Title="Action"
Description="Action Section"
ToolTip="Action Page"/>
<MapNode ImageUrl="~\Images\Drama.gif"
Title="Drama"
Description="Drama Section"
ToolTip="Drama Page"/>
<MapNode ImageUrl="~\Images\Musical.gif"
Title="Musical"
Description="Musical Section"
ToolTip="Musical Page"/>
</MapNode>
</MapNode>
注釈
MenuItemBinding オブジェクトを作成するときは、バインドの条件を指定する必要があります。 条件は、データ項目をメニュー項目にバインドする必要があるタイミングを示します。 Depth プロパティ、DataMember プロパティ、またはその両方を指定できます。
MenuItemBinding オブジェクトを適用するメニューの深さを指定するには、Depth プロパティを使用します。 たとえば、次の MenuItemBinding 宣言では、データ ソースの Name フィールドと ID フィールドをそれぞれ、深さが 0 のすべてのメニュー項目の Text プロパティと Value プロパティにバインドします。
<asp:MenuItemBinding Depth="0" TextField="Name" ValueField="ID">
場合によっては、深度とデータ メンバーの両方を指定するメニュー項目バインドを作成する必要があります。 これは、データ ソースに同じデータ メンバー値を持つ異なるレベルの項目が含まれている場合によく使用されます。 たとえば、XML ファイル内のさまざまなレベルで表示される <Item> 要素を持つことができます。 次の MenuItemBinding 宣言は、同一のデータ メンバーに適用されるメニュー項目のバインドを異なるメニューの深さで指定する方法を示しています。
<asp:MenuItemBinding DataMember="Item" Depth="1" TextField="Title">
<asp:MenuItemBinding DataMember="Item" Depth="2" TextField="ISBN">
メニュー項目バインドが深度とデータ メンバーなしで定義されている場合、メニュー項目バインドはメニュー内のすべてのメニュー項目に適用されます。 これは、メニューの深さに関係なく、すべてのデータ項目が同じプロパティを持ち、同じように表示する必要がある場合に一般的に使用されます。
バインド条件が確立されたら、値にバインドできる MenuItem オブジェクトのプロパティをバインドできます。 データ項目のフィールドまたは静的な値にバインドできます。 静的な値にバインドすると、MenuItemBinding オブジェクトが適用されるすべてのMenuItem オブジェクトが同じ値を共有します。 フィールドにバインドされたプロパティには、データ ソースのフィールドの値が含まれます。
競合 MenuItemBinding オブジェクトが定義されている場合、 Menu コントロールはメニュー項目のバインドを次の優先順位で適用します。
深度メンバーとデータ メンバーの両方を定義して一致する MenuItemBinding オブジェクト。
データ メンバーのみを定義して一致する MenuItemBinding オブジェクト。
深度のみを定義して一致する MenuItemBinding オブジェクト。
深度もデータ メンバーも定義しない MenuItemBinding オブジェクト。 (この種類のメニュー項目バインドは、メニュー内のすべてのメニュー項目に適用されます)。
データ ソースに一致するものがない MenuItemBinding オブジェクト。 この場合、データ項目の
ToString()メソッドによって返される値は、MenuItemBinding オブジェクトが適用されるメニュー項目のTextプロパティとValueプロパティにバインドされます。