TreeView.ParentNodeStyle 屬性

定義

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

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

屬性值

TreeNodeStyle 的參考,表示 TreeView 控制項中父節點的樣式。

屬性

範例

下列程式碼範例示範如何使用 ParentNodeStyle 屬性來控制 控制項中 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 ParentNodeStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView ParentNodeStyle Example</h3>
      
      <!-- Declaratively set the ParentNodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        ParentNodeStyle-ForeColor="Green"
        ParentNodeStyle-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="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 ParentNodeStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView ParentNodeStyle Example</h3>
      
      <!-- Declaratively set the ParentNodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        ParentNodeStyle-ForeColor="Green"
        ParentNodeStyle-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>

備註

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

  1. NodeStyle.

  2. RootNodeStyleParentNodeStyleLeafNodeStyle ,視節點類型而定。 LevelStyles如果已定義集合,則此時會套用該集合,並覆寫其他節點樣式屬性。

  3. SelectedNodeStyle.

  4. HoverNodeStyle.

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

適用於

另請參閱