TemplateDefinition Třída

Definice

Poskytuje vlastnosti a metody, které definují prvek šablony v ovládacím prvku webového serveru v době návrhu.

public ref class TemplateDefinition : System::Web::UI::Design::DesignerObject
public class TemplateDefinition : System.Web.UI.Design.DesignerObject
type TemplateDefinition = class
    inherit DesignerObject
Public Class TemplateDefinition
Inherits DesignerObject
Dědičnost
TemplateDefinition

Příklady

Následující příklad kódu ukazuje, jak odvodit vlastní třídu z ControlDesigner třídy . Tento návrhář ovládacích prvků podporuje ovládací prvek se čtyřmi možnými šablonami.

Pokud si to chcete vyzkoušet, přidejte odkaz na sestavení System.Design.dll, zkompilujte kód a pak se v návrhovém hostiteli, jako je Visual Studio 2005, podívejte na stránku v návrhovém zobrazení. Vyberte ovládací prvek, kliknutím na seznam akcí vyberte šablonu, kterou chcete upravit, a pak pomocí funkce přetažení přesuňte ovládací prvky do šablony.

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;

namespace ASPNet.Design.Samples
{
    // Set an attribute reference to the designer, and define 
    // the HTML markup that the toolbox will write into the source.
    [Designer(typeof(TemplateGroupsSampleDesigner)),
        ToolboxData("<{0}:TemplateGroupsSample runat=server></{0}:TemplateGroupsSample>")]
    public sealed class TemplateGroupsSample : WebControl, INamingContainer
    {
        // Field for the templates
        private ITemplate[] _templates;

        // Constructor
        public TemplateGroupsSample()
        {
            _templates = new ITemplate[4];
        }

        // For each template property, set the designer attributes 
        // so the property does not appear in the property grid, but 
        // changes to the template are persisted in the control.
        [Browsable(false),
            PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate Template1
        {
            get { return _templates[0]; }
            set { _templates[0] = value; }
        }
        [Browsable(false),
            PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate Template2
        {
            get { return _templates[1]; }
            set { _templates[1] = value; }
        }
        [Browsable(false),
            PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate Template3
        {
            get { return _templates[2]; }
            set { _templates[2] = value; }
        }
        [Browsable(false),
            PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate Template4
        {
            get { return _templates[3]; }
            set { _templates[3] = value; }
        }

        protected override void CreateChildControls()
        {
            // Instantiate each template inside a panel
            // then add the panel to the Controls collection
            for (int i = 0; i < 4; i++)
            {
                Panel pan = new Panel();
                _templates[i].InstantiateIn(pan);
                this.Controls.Add(pan);
            }
        }
    }

    // Designer for the TemplateGroupsSample control
    public class TemplateGroupsSampleDesigner : ControlDesigner
    {
        TemplateGroupCollection col = null;

        public override void Initialize(IComponent component)
        {
            // Initialize the base
            base.Initialize(component);
            // Turn on template editing
            SetViewFlags(ViewFlags.TemplateEditing, true);
        }

        // Add instructions to the placeholder view of the control
        public override string GetDesignTimeHtml()
        {
            return CreatePlaceHolderDesignTimeHtml("Click here and use " +
                "the task menu to edit the templates.");
        }

        public override TemplateGroupCollection TemplateGroups
        {
            get
            {

                if (col == null)
                {
                    // Get the base collection
                    col = base.TemplateGroups;

                    // Create variables
                    TemplateGroup tempGroup;
                    TemplateDefinition tempDef;
                    TemplateGroupsSample ctl;

                    // Get reference to the component as TemplateGroupsSample
                    ctl = (TemplateGroupsSample)Component;

                    // Create a TemplateGroup
                    tempGroup = new TemplateGroup("Template Set A");

                    // Create a TemplateDefinition
                    tempDef = new TemplateDefinition(this, "Template A1", 
                        ctl, "Template1", true);

                    // Add the TemplateDefinition to the TemplateGroup
                    tempGroup.AddTemplateDefinition(tempDef);

                    // Create another TemplateDefinition
                    tempDef = new TemplateDefinition(this, "Template A2", 
                        ctl, "Template2", true);

                    // Add the TemplateDefinition to the TemplateGroup
                    tempGroup.AddTemplateDefinition(tempDef);

                    // Add the TemplateGroup to the TemplateGroupCollection
                    col.Add(tempGroup);

                    // Create another TemplateGroup and populate it
                    tempGroup = new TemplateGroup("Template Set B");
                    tempDef = new TemplateDefinition(this, "Template B1", 
                        ctl, "Template3", true);
                    tempGroup.AddTemplateDefinition(tempDef);
                    tempDef = new TemplateDefinition(this, "Template B2", 
                        ctl, "Template4", true);
                    tempGroup.AddTemplateDefinition(tempDef);

                    // Add the TemplateGroup to the TemplateGroupCollection
                    col.Add(tempGroup);
                }

                return col;
            }
        }

        // Do not allow direct resizing unless in TemplateMode
        public override bool AllowResize
        {
            get
            {
                if (this.InTemplateMode)
                    return true;
                else
                    return false;
            }
        }
    }
}
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design

Namespace ASPNet.Design.Samples

    ' Set an attribute reference to the designer, and define 
    ' the HTML markup that the toolbox will write into the source.
    <Designer(GetType(TemplateGroupsSampleDesigner)), _
        ToolboxData("<{0}:TemplateGroupsSample runat=server></{0}:TemplateGroupsSample>")> _
    Public Class TemplateGroupsSample
        Inherits WebControl
        Implements INamingContainer

        ' Field for the templates
        Private _templates() As ITemplate

        ' Constructor
        Public Sub New()
            ReDim _templates(4)
        End Sub

        ' For each template property, set the designer attributes 
        ' so the property does not appear in the property grid, but 
        ' changes to the template are persisted in the control.
        <Browsable(False), _
            PersistenceMode(PersistenceMode.InnerProperty)> _
        Public Property Template1() As ITemplate
            Get
                Return _templates(0)
            End Get
            Set(ByVal Value As ITemplate)
                _templates(0) = Value
            End Set
        End Property
        <Browsable(False), _
            PersistenceMode(PersistenceMode.InnerProperty)> _
        Public Property Template2() As ITemplate
            Get
                Return _templates(1)
            End Get
            Set(ByVal Value As ITemplate)
                _templates(1) = Value
            End Set
        End Property
        <Browsable(False), _
            PersistenceMode(PersistenceMode.InnerProperty)> _
        Public Property Template3() As ITemplate
            Get
                Return _templates(2)
            End Get
            Set(ByVal Value As ITemplate)
                _templates(2) = Value
            End Set
        End Property
        <Browsable(False), _
            PersistenceMode(PersistenceMode.InnerProperty)> _
        Public Property Template4() As ITemplate
            Get
                Return _templates(3)
            End Get
            Set(ByVal Value As ITemplate)
                _templates(3) = Value
            End Set
        End Property

        Protected Overrides Sub CreateChildControls()
            ' Instantiate the template inside the panel
            ' then add the panel to the Controls collection
            Dim i As Integer

            For i = 0 To 3
                Dim pan As New Panel()
                _templates(i).InstantiateIn(pan)
                Me.Controls.Add(pan)
            Next
        End Sub

    End Class

    ' Designer for the TemplateGroupsSample class
    Public Class TemplateGroupsSampleDesigner
        Inherits System.Web.UI.Design.ControlDesigner

        Private col As TemplateGroupCollection = Nothing

        Public Overrides Sub Initialize(ByVal Component As IComponent)
            ' Initialize the base
            MyBase.Initialize(Component)
            ' Turn on template editing
            SetViewFlags(ViewFlags.TemplateEditing, True)
        End Sub

        ' Add instructions to the placeholder view of the control
        Public Overloads Overrides Function GetDesignTimeHtml() As String
            Return CreatePlaceHolderDesignTimeHtml("Click here and use " & _
                "the task menu to edit the templates.")
        End Function

        Public Overrides ReadOnly Property TemplateGroups() As TemplateGroupCollection
            Get
                If IsNothing(col) Then
                    ' Get the base collection
                    col = MyBase.TemplateGroups

                    ' Create variables
                    Dim tempGroup As TemplateGroup
                    Dim tempDef As TemplateDefinition
                    Dim ctl As TemplateGroupsSample

                    ' Get reference to the component as TemplateGroupsSample
                    ctl = CType(Component, TemplateGroupsSample)

                    ' Create a TemplateGroup
                    tempGroup = New TemplateGroup("Template Set A")

                    ' Create a TemplateDefinition
                    tempDef = New TemplateDefinition(Me, "Template A1", ctl, "Template1", True)

                    ' Add the TemplateDefinition to the TemplateGroup
                    tempGroup.AddTemplateDefinition(tempDef)

                    ' Create another TemplateDefinition
                    tempDef = New TemplateDefinition(Me, "Template A2", ctl, "Template2", True)

                    ' Add the TemplateDefinition to the TemplateGroup
                    tempGroup.AddTemplateDefinition(tempDef)

                    ' Add the TemplateGroup to the TemplateGroupCollection
                    col.Add(tempGroup)

                    ' Create another TemplateGroup and populate it
                    tempGroup = New TemplateGroup("Template Set B")
                    tempDef = New TemplateDefinition(Me, "Template B1", ctl, "Template3", True)
                    tempGroup.AddTemplateDefinition(tempDef)
                    tempDef = New TemplateDefinition(Me, "Template B2", ctl, "Template4", True)
                    tempGroup.AddTemplateDefinition(tempDef)

                    ' Add the TemplateGroup to the TemplateGroupCollection
                    col.Add(tempGroup)
                End If

                Return col
            End Get
        End Property

        ' Do not allow direct resizing unless in TemplateMode
        Public Overrides ReadOnly Property AllowResize() As Boolean
            Get
                If Me.InTemplateMode Then
                    Return True
                Else
                    Return False
                End If
            End Get
        End Property
    End Class
End Namespace
<%@ Page Language="VB" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="ASPNet.Design.Samples" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
       <aspSample:TemplateGroupsSample runat="server" ID="TGSample1">
       </aspSample:TemplateGroupsSample>
    
    </div>
    </form>
</body>
</html>

Poznámky

Třída TemplateDefinition poskytuje základní definiční třídu šablony, která může být zděděna a rozšířena pro návrháře ovládacích prvků při poskytování podpory pro ovládací prvky šablony v návrhovém hostiteli, jako je Visual Studio 2005. Hostitel návrhu používá vlastnosti a metody TemplateDefinition třídy k usnadnění vytváření a úprav šablony v době návrhu.

Konstruktory

TemplateDefinition(ControlDesigner, String, Object, String)

Inicializuje novou instanci TemplateDefinition třídy pomocí zadaného návrháře, názvu šablony, šablony a názvu vlastnosti.

TemplateDefinition(ControlDesigner, String, Object, String, Boolean)

Inicializuje novou instanci třídy pomocí zadaného TemplateDefinition návrháře, názvu šablony, šablony, názvu vlastnosti a zda omezit obsah šablony na ovládací prvky webového serveru.

TemplateDefinition(ControlDesigner, String, Object, String, Style)

Inicializuje novou instanci TemplateDefinition třídy pomocí zadaného návrháře, názvu šablony, šablony, názvu vlastnosti a Style objektu.

TemplateDefinition(ControlDesigner, String, Object, String, Style, Boolean)

Inicializuje novou instanci TemplateDefinition třídy pomocí zadaného návrháře, názvu šablony, šablony, názvu vlastnosti, Style objektu a zda omezit obsah na ovládací prvky webového serveru.

Vlastnosti

AllowEditing

Získá hodnotu, která označuje, zda šablona má povolit úpravy jeho obsahu.

Content

Získá nebo nastaví kód HTML představující obsah šablony.

Designer

Získá přidruženou komponentu návrháře.

(Zděděno od DesignerObject)
Name

Získá název objektu.

(Zděděno od DesignerObject)
Properties

Získá vlastnosti objektu.

(Zděděno od DesignerObject)
ServerControlsOnly

Načte hodnotu označující, zda má šablona omezit obsah na ovládací prvky webového serveru, jak je nastaveno v konstruktoru TemplateDefinition . Tato vlastnost je jen ke čtení.

Style

Načte styl, který by měl být použit na šablonu, jak je nastaveno v konstruktoru TemplateDefinition . Tato vlastnost je jen ke čtení.

SupportsDataBinding

Načte nebo nastaví hodnotu označující, zda šablona podporuje datové vazby.

TemplatedObject

Načte komponentu, ve které se nachází šablona. Tato vlastnost je jen ke čtení.

TemplatePropertyName

Načte název vlastnosti šablony, kterou by měl hostitel návrhu zobrazit v mřížce vlastností.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetService(Type)

Získá službu z hostitele návrhu, jak je identifikováno zadaným typem.

(Zděděno od DesignerObject)
GetType()

Type Získá z aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

IServiceProvider.GetService(Type)

Popis tohoto člena najdete v tématu GetService(Type).

(Zděděno od DesignerObject)

Metody rozšíření

GetKeyedService<T>(IServiceProvider, Object)

Získá službu typu T z .IServiceProvider

GetKeyedServices(IServiceProvider, Type, Object)

Získá výčet služeb typu serviceType z IServiceProvider.

GetKeyedServices<T>(IServiceProvider, Object)

Získá výčet služeb typu T z IServiceProvider.

GetRequiredKeyedService(IServiceProvider, Type, Object)

Získá službu typu serviceType z .IServiceProvider

GetRequiredKeyedService<T>(IServiceProvider, Object)

Získá službu typu T z .IServiceProvider

CreateAsyncScope(IServiceProvider)

Vytvoří nový AsyncServiceScope , který lze použít k vyřešení služeb s vymezeným oborem.

CreateScope(IServiceProvider)

Vytvoří nový IServiceScope , který lze použít k vyřešení služeb s vymezeným oborem.

GetRequiredService(IServiceProvider, Type)

Získejte službu typu serviceType z .IServiceProvider

GetRequiredService<T>(IServiceProvider)

Získejte službu typu T z .IServiceProvider

GetService<T>(IServiceProvider)

Získejte službu typu T z .IServiceProvider

GetServices(IServiceProvider, Type)

Získejte výčet služeb typu serviceType z .IServiceProvider

GetServices<T>(IServiceProvider)

Získejte výčet služeb typu T z .IServiceProvider

GetFakeLogCollector(IServiceProvider)

Získá objekt, který shromažďuje záznamy protokolu odeslané do falešné protokolovací nástroje.

GetFakeRedactionCollector(IServiceProvider)

Získá falešné redactor kolektor instance z kontejneru injektáž závislostí.

Platí pro

Viz také