SiteMapPath.RootNodeTemplate SiteMapPath.RootNodeTemplate SiteMapPath.RootNodeTemplate SiteMapPath.RootNodeTemplate Property

Definizione

Ottiene o imposta un modello di controllo da utilizzare per il nodo radice di un percorso di navigazione nel sito.Gets or sets a control template to use for the root node of a site navigation path.

public:
 virtual property System::Web::UI::ITemplate ^ RootNodeTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.SiteMapNodeItem))]
public virtual System.Web.UI.ITemplate RootNodeTemplate { get; set; }
member this.RootNodeTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property RootNodeTemplate As ITemplate

Valore della proprietà

Un oggetto ITemplate che implementa il metodo InstantiateIn(Control) per il rendering di contenuto personalizzato per il nodo radice di un percorso di navigazione.An ITemplate object that implements the InstantiateIn(Control) method, to render custom content for the root node of a navigation path.

Esempi

Nell'esempio di codice seguente viene illustrato come definire a livello di codice una classe ITemplate che implementa l'interfaccia Image per eseguire il wrapping di un controllo.The following code example demonstrates how to programmatically define a class that implements the ITemplate interface to wrap an Image control. Quindi, la RootNodeTemplate proprietà viene impostata su un'istanza della classe.Then, the RootNodeTemplate property is set to an instance of the class.

<%@ Page language="c#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
        // Create the SiteMapPath control.
        SiteMapPath navpath = new SiteMapPath();

        // Make the root node look unique.
        // The Image that you can use in your Web page is an
        // instance of the WebControls.Image class, not the
        // Drawing.Image class.
        System.Web.UI.WebControls.Image rootNodeImage =
            new System.Web.UI.WebControls.Image();
        rootNodeImage.ImageUrl = "myimage.jpg";
        ImageTemplate rootNodeImageTemplate = new ImageTemplate();
        rootNodeImageTemplate.MyImage = rootNodeImage;
        navpath.RootNodeTemplate = rootNodeImageTemplate;

        // Make the current node look unique.
        Style currentNodeStyle = new Style();
        navpath.CurrentNodeStyle.ForeColor = System.Drawing.Color.AliceBlue;
        navpath.CurrentNodeStyle.BackColor = System.Drawing.Color.Bisque;

        // Set the path separator to be something other
        // than the default.
        navpath.PathSeparator = "::";

        PlaceHolder1.Controls.Add(navpath);
    }


    // A simple Template class to wrap an image.
    public class ImageTemplate : ITemplate
    {
        private System.Web.UI.WebControls.Image myImage;
        public System.Web.UI.WebControls.Image MyImage
        {
            get
            {
                return myImage;
            }
            set
            {
                myImage = value;
            }
        }
        public void InstantiateIn(Control container)
        {
            container.Controls.Add(MyImage);
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>About Our Company</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

      <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>

      <h1>About Our Company</h1>

      <p>Our company was founded in 1886.</p>

      <p>We use only the finest ingredients, organically grown fruits, and
      natural spices in our homemade pies. We use no artificial preservatives
      or coloring agents. We would not have it any other way!</p>

    </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">
<script runat="server">

    Private Sub Page_Load(sender As Object, e As EventArgs)
        ' Create the SiteMapPath control.
        Dim navpath As New SiteMapPath()

        ' Make the root node look unique.
        ' The Image that you can use in your Web page is an
        ' instance of the WebControls.Image class, not the
        ' Drawing.Image class.
        Dim rootNodeImage As New System.Web.UI.WebControls.Image()
        rootNodeImage.ImageUrl = "myimage.jpg"
        Dim rootNodeImageTemplate As New ImageTemplate()
        rootNodeImageTemplate.MyImage = rootNodeImage
        navpath.RootNodeTemplate = rootNodeImageTemplate

        ' Make the current node look unique.
        Dim currentNodeStyle As New Style()
        navpath.CurrentNodeStyle.ForeColor = System.Drawing.Color.AliceBlue
        navpath.CurrentNodeStyle.BackColor = System.Drawing.Color.Bisque

        ' Set the path separator to be something other
        ' than the default.
        navpath.PathSeparator = "::"

        PlaceHolder1.Controls.Add(navpath)
    End Sub ' Page_Load


    ' A simple Template class to wrap an image.
    Public Class ImageTemplate
      Implements ITemplate

        Private anImage As System.Web.UI.WebControls.Image
        Public Property MyImage As System.Web.UI.WebControls.Image
          Get
            return anImage
          End Get
          Set
            anImage = value
          End Set
        End Property ' MyImage

        Public Overridable Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
            container.Controls.Add(MyImage)
        End Sub ' InstantiateIn

    End Class ' ImageTemplate
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>About Our Company</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

      <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>

      <h1>About Our Company</h1>

      <p>Our company was founded in 1886.</p>

      <p>We use only the finest ingredients, organically grown fruits, and
      natural spices in our homemade pies. We use no artificial preservatives
      or coloring agents. We would not have it any other way!</p>

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

Commenti

Impostare su un ITemplate oggetto per usare un Image controllo o un altro controllo, ad esempio un Label come elemento dell'interfaccia utente del nodo radice anziché una stringa. RootNodeTemplateSet the RootNodeTemplate to an ITemplate object to use an Image control or some other control, such as a Label as the root node's user interface element instead of a string.

Se la RootNodeTemplate proprietà è impostata, il modello sostituisce sia il testo del nodo di navigazione radice visualizzato RootNodeStyle che qualsiasi applicato.If the RootNodeTemplate property is set, the template overrides both the root navigation node text displayed and any RootNodeStyle applied to it. Il modello esegue anche l' CurrentNodeTemplate override CurrentNodeStyle delle proprietà e se la pagina radice è la pagina attualmente visualizzata.The template also overrides the CurrentNodeTemplate and CurrentNodeStyle properties if the root page is the currently displayed page.

È possibile impostare la RootNodeTemplate proprietà in modo dichiarativo su qualsiasi controllo server Web e l'infrastruttura ASP.NET esegue i passaggi necessari per eseguire il wrapping del controllo server Web ITemplatecome.You can declaratively set the RootNodeTemplate property to any Web server control, and the ASP.NET infrastructure performs the necessary steps to wrap the Web server control as an ITemplate. Tuttavia, i controlli server Web non implementano ITemplate l'interfaccia. Pertanto, quando si utilizzano le ITemplate proprietà a livello di programmazione, è necessario ITemplate scrivere un wrapper per qualsiasi codice modello.However, Web server controls do not implement the ITemplate interface; therefore, when you work with the ITemplate properties programmatically, you must write an ITemplate wrapper for any template code. Quindi, la RootNodeTemplate proprietà viene impostata su un'istanza ITemplate del wrapper.Then, the RootNodeTemplate property is set to an instance of the ITemplate wrapper.

Si applica a

Vedi anche