Breyta

Deila með


TreeView.LeafNodeStyle Property

Definition

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of leaf nodes.

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

Property Value

A reference to the TreeNodeStyle that represents the style of the leaf nodes in the TreeView.

Attributes

Examples

The following code example demonstrates how to use the LeafNodeStyle property to control the appearance of the leaf nodes in the TreeView control.


<%@ 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 LeafNodeStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView LeafNodeStyle Example</h3>
      
      <!-- Declaratively set the LeafNodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        LeafNodeStyle-ForeColor="Green"
        LeafNodeStyle-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 LeafNodeStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView LeafNodeStyle Example</h3>
      
      <!-- Declaratively set the LeafNodeStyle settings. --> 
      <asp:TreeView id="LinksTreeView"
        LeafNodeStyle-ForeColor="Green"
        LeafNodeStyle-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>

Remarks

Use the LeafNodeStyle property to control the appearance of the leaf nodes in the TreeView control. This property is read-only; however, you can set the properties of the TreeNodeStyle object it returns. The properties can be set declaratively in the form Property-Subproperty, where Subproperty is a property of the TreeNodeStyle object (for example, LeafNodeStyle-ForeColor). The properties can also be set programmatically in the form Property.Subproperty (for example, LeafNodeStyle.ForeColor). Common settings usually include a custom background color, foreground color, font properties, and node spacing. Style properties are applied in the following order of precedence:

  1. NodeStyle.

  2. RootNodeStyle, ParentNodeStyle, or LeafNodeStyle, depending on the node type. If the LevelStyles collection is defined, it is applied at this time, overriding the other node style properties.

  3. SelectedNodeStyle.

  4. HoverNodeStyle.

If you need to generate table of contents-style navigation menus where nodes at a certain level should have the same appearance, regardless of whether they have child nodes, you might consider using the LevelStyles property instead of setting the individual style properties.

Applies to

See also