SiteMapPath.RootNodeTemplate Właściwość

Definicja

Pobiera lub ustawia szablon kontrolki do użycia dla węzła głównego ścieżki nawigacji witryny.

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; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.SiteMapNodeItem))>]
member this.RootNodeTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property RootNodeTemplate As ITemplate

Wartość właściwości

ITemplate

ITemplate Obiekt, który implementuje metodę InstantiateIn(Control) , aby renderować zawartość niestandardową dla węzła głównego ścieżki nawigacji.

Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak programowo zdefiniować klasę, która implementuje ITemplate interfejs w celu opakowania kontrolki Image . RootNodeTemplate Następnie właściwość jest ustawiona na wystąpienie klasy.

<%@ 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>

Uwagi

RootNodeTemplate Ustaw obiekt na ITemplate obiekt, aby użyć kontrolki Image lub innej kontrolki, takiej jak Label element interfejsu użytkownika węzła głównego zamiast ciągu.

RootNodeTemplate Jeśli właściwość jest ustawiona, szablon zastępuje zarówno tekst węzła nawigacji głównej, jak i dowolny RootNodeStyle zastosowany do niego. Szablon zastępuje CurrentNodeTemplate również właściwości i CurrentNodeStyle , jeśli strona główna jest aktualnie wyświetlana.

Właściwość można deklaratywnie ustawić RootNodeTemplate na dowolną kontrolkę serwera sieci Web, a infrastruktura ASP.NET wykonuje niezbędne kroki, aby opakowować kontrolkę serwera sieci Web jako ITemplate. Jednak kontrolki serwera sieci Web nie implementują interfejsu ITemplate , dlatego podczas pracy z właściwościami ITemplate programowo należy napisać otokę ITemplate dla dowolnego kodu szablonu. RootNodeTemplate Następnie właściwość jest ustawiona na wystąpienie ITemplate otoki.

Dotyczy

Zobacz też