TreeView.NodeStyle Propriedade

Definição

Obtém uma referência ao objeto TreeNodeStyle que permite definir a aparência padrão dos nós no controle TreeView.Gets a reference to the TreeNodeStyle object that allows you to set the default appearance of the nodes in the TreeView control.

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

Valor da propriedade

TreeNodeStyle

Uma referência ao TreeNodeStyle que representa o estilo padrão de um nó.A reference to the TreeNodeStyle that represents the default style of a node.

Atributos

Exemplos

O exemplo de código a seguir demonstra como usar a NodeStyle propriedade para controlar a aparência de nós no TreeView controle.The following code example demonstrates how to use the NodeStyle property to control the appearance of 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 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>

Comentários

Use a NodeStyle propriedade para controlar a aparência padrão de um nó no TreeView controle.Use the NodeStyle property to control the default appearance of a node in the TreeView control. Esta propriedade é somente leitura; no entanto, você pode definir as propriedades do TreeNodeStyle objeto retornado.This property is read-only; however, you can set the properties of the TreeNodeStyle object it returns. As propriedades podem ser definidas declarativamente no formulário Property-Subproperty , em que Subproperty é uma propriedade do TreeNodeStyle objeto (por exemplo, NodeStyle-ForeColor ).The properties can be set declaratively in the form Property-Subproperty, where Subproperty is a property of the TreeNodeStyle object (for example, NodeStyle-ForeColor). As propriedades também podem ser definidas programaticamente no formulário Property.Subproperty (por exemplo, NodeStyle.ForeColor ).The properties can also be set programmatically in the form Property.Subproperty (for example, NodeStyle.ForeColor). As configurações comuns geralmente incluem uma cor de fundo personalizada, cor de primeiro plano, propriedades de fonte e espaçamento de nó.Common settings usually include a custom background color, foreground color, font properties, and node spacing. As propriedades de estilo são aplicadas na seguinte ordem de precedência:Style properties are applied in the following order of precedence:

  1. NodeStyle.NodeStyle.

  2. RootNodeStyle, ParentNodeStyle ou LeafNodeStyle , dependendo do tipo de nó.RootNodeStyle, ParentNodeStyle, or LeafNodeStyle, depending on the node type. Se a LevelStyles coleção for definida, ela será aplicada neste momento, substituindo as outras propriedades de estilo de nó.If the LevelStyles collection is defined, it is applied at this time, overriding the other node style properties.

  3. SelectedNodeStyle.SelectedNodeStyle.

  4. HoverNodeStyle.HoverNodeStyle.

Observação

As configurações de estilo de nó correspondentes RootNodeStyle nas ParentNodeStyle Propriedades, ou LeafNodeStyle substituem as configurações de estilo da NodeStyle propriedade.The corresponding node style settings in the RootNodeStyle, ParentNodeStyle, or LeafNodeStyle properties override the style settings of the NodeStyle property.

Se você precisar gerar tabelas de menus de navegação de estilo de conteúdo em que os nós em um determinado nível devem ter a mesma aparência, independentemente de terem nós filho, você pode considerar o uso da LevelStyles propriedade em vez de definir as propriedades de estilo individuais.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.

Aplica-se a

Confira também