TemplateDefinition 클래스

정의

디자인 타임에 웹 서버 컨트롤의 템플릿 요소를 정의하는 속성과 메서드를 제공합니다.

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
상속
TemplateDefinition

예제

다음 코드 예제에서는 클래스에서 ControlDesigner 사용자 지정 클래스를 파생 하는 방법을 보여 줍니다. 이 컨트롤 디자이너는 4개의 가능한 템플릿이 있는 컨트롤을 지원합니다.

이를 시도하려면 System.Design.dll 어셈블리에 대한 참조를 추가하고 코드를 컴파일한 다음 Visual Studio 2005와 같은 디자인 호스트에서 디자인 보기의 페이지를 확인합니다. 컨트롤을 선택하고 작업 목록을 클릭하여 수정할 템플릿을 선택한 다음 끌어서 놓기 기능을 사용하여 컨트롤을 템플릿으로 이동합니다.

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>

설명

이 클래스는 TemplateDefinition 컨트롤 디자이너가 Visual Studio 2005와 같은 디자인 호스트에서 템플릿 기반 컨트롤에 대한 지원을 제공하는 데 사용할 수 있도록 상속하고 확장할 수 있는 기본 템플릿 정의 클래스를 제공합니다. 디자인 호스트는 클래스의 속성과 메서드를 TemplateDefinition 사용하여 디자인 타임에 템플릿을 쉽게 만들고 편집할 수 있습니다.

생성자

TemplateDefinition(ControlDesigner, String, Object, String)

제공된 디자이너, 템플릿 이름, 템플릿 및 속성 이름을 사용하여 TemplateDefinition 클래스의 새 인스턴스를 초기화합니다.

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

제공된 디자이너, 템플릿 이름, 템플릿, 속성 이름 및 템플릿 내용에 웹 서버 컨트롤만 사용할지 여부를 사용하여 TemplateDefinition 클래스의 새 인스턴스를 초기화합니다.

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

제공된 디자이너, 템플릿 이름, 템플릿, 속성 이름 및 TemplateDefinition 개체를 사용하여 Style 클래스의 새 인스턴스를 초기화합니다.

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

제공된 디자이너, 템플릿 이름, 템플릿, 속성 이름, TemplateDefinition 개체 및 내용에 웹 서버 컨트롤만 사용할지 여부를 사용하여 Style 클래스의 새 인스턴스를 초기화합니다.

속성

AllowEditing

템플릿에서 내용 편집을 허용할지 여부를 나타내는 값을 가져옵니다.

Content

템플릿 내용을 나타내는 HTML 태그를 가져오거나 설정합니다.

Designer

연결된 디자이너 구성 요소를 가져옵니다.

(다음에서 상속됨 DesignerObject)
Name

개체의 이름을 가져옵니다.

(다음에서 상속됨 DesignerObject)
Properties

개체의 속성을 가져옵니다.

(다음에서 상속됨 DesignerObject)
ServerControlsOnly

TemplateDefinition 생성자에 설정된 대로, 템플릿이 내용을 웹 서버 컨트롤에 한정할지 여부를 나타내는 값을 검색합니다. 이 속성은 읽기 전용입니다.

Style

TemplateDefinition 생성자에 설정된 대로, 템플릿에 적용될 스타일을 검색합니다. 이 속성은 읽기 전용입니다.

SupportsDataBinding

템플릿이 데이터 바인딩을 지원하는지 여부를 나타내는 값을 검색하거나 설정합니다.

TemplatedObject

템플릿이 포함된 구성 요소를 검색합니다. 이 속성은 읽기 전용입니다.

TemplatePropertyName

디자인 호스트가 속성 표에 표시할 템플릿의 속성 이름을 검색합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetService(Type)

제공된 형식으로 식별되는 서비스를 디자인 호스트에서 가져옵니다.

(다음에서 상속됨 DesignerObject)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IServiceProvider.GetService(Type)

이 멤버에 대한 설명은 GetService(Type)를 참조하세요.

(다음에서 상속됨 DesignerObject)

적용 대상

추가 정보