TreeView.NodeStyle 屬性

定義

取得 TreeNodeStyle 物件的參考,這個物件可讓您設定 TreeView 控制項中節點的預設外觀。

public:
 property System::Web::UI::WebControls::TreeNodeStyle ^ NodeStyle { System::Web::UI::WebControls::TreeNodeStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TreeNodeStyle NodeStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.NodeStyle : System.Web.UI.WebControls.TreeNodeStyle
Public ReadOnly Property NodeStyle As TreeNodeStyle

屬性值

TreeNodeStyle 的參考,表示節點的預設樣式。

屬性

範例

下列程式碼範例示範如何使用 NodeStyle 屬性來控制 控制項中 TreeView 節點的外觀。


<%@ 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>TreeView NodeStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView NodeStyle Example</h3>
      
      <!-- Declaratively set the NodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        NodeStyle-ForeColor="Green"
        NodeStyle-VerticalPadding="0"  
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </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>TreeView NodeStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView NodeStyle Example</h3>
      
      <!-- Declaratively set the NodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        NodeStyle-ForeColor="Green"
        NodeStyle-VerticalPadding="0"  
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </form>
  </body>
</html>

備註

NodeStyle使用 屬性來控制 控制項中 TreeView 節點的預設面板。 此屬性是唯讀的;不過,您可以設定它所傳回之 TreeNodeStyle 物件的屬性。 屬性可以宣告方式在 表單 Property-Subproperty 中設定,其中 Subproperty 是物件的屬性 TreeNodeStyle (例如, NodeStyle-ForeColor) 。 屬性也可以在表單 Property.Subproperty 中以程式設計方式設定,例如 () NodeStyle.ForeColor 。 常見的設定通常包括自訂背景色彩、前景色彩、字型屬性和節點間距。 樣式屬性會以下列優先順序套用:

  1. NodeStyle.

  2. RootNodeStyleParentNodeStyle 、 或 LeafNodeStyle ,視節點類型而定。 LevelStyles如果定義集合,則此時會套用它,覆寫其他節點樣式屬性。

  3. SelectedNodeStyle.

  4. HoverNodeStyle.

注意

ParentNodeStyleLeafNodeStyle 屬性中的 RootNodeStyle 對應節點樣式設定會覆寫 屬性的 NodeStyle 樣式設定。

如果您需要產生目錄樣式導覽功能表,其中特定層級的節點應該具有相同的外觀,不論節點是否具有子節點,您可能會考慮使用 LevelStyles 屬性,而不是設定個別樣式屬性。

適用於

另請參閱