TemplateDefinitionとは? わかりやすく解説

TemplateDefinition クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

デザイン時に Web サーバー コントロールテンプレート要素定義するプロパティおよびメソッド提供します

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Class TemplateDefinition
    Inherits DesignerObject
Dim instance As TemplateDefinition
public class TemplateDefinition : DesignerObject
public ref class TemplateDefinition : public
 DesignerObject
public class TemplateDefinition extends DesignerObject
public class TemplateDefinition extends
 DesignerObject
解説解説
使用例使用例

ControlDesigner クラスからカスタム クラス派生する方法次のコード例示します。このコントロール デザイナは、4 つテンプレートを持つコントロールサポートします

これを試すには、System.Design.dll アセンブリへの参照追加しコードコンパイルしてから、Visual Studio 2005 などのデザイン ホストデザイン ビューページ開きますコントロール選択しアクション リストクリックして変更するテンプレート選択します次にドラッグ アンド ドロップ機能使用してコントロールテンプレート内に移動します

Imports Microsoft.VisualBasic
Imports System
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
<br /><span space="preserve">...</span><br
 /><%@ 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  >
<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>
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;
            }
        }
    }
}
継承階層継承階層
System.Object
   System.Web.UI.Design.DesignerObject
    System.Web.UI.Design.TemplateDefinition
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TemplateDefinition メンバ
System.Web.UI.Design 名前空間
ControlDesigner クラス
ControlDesigner.TemplateGroups プロパティ
TemplatedControlDesigner クラス
その他の技術情報
デザインサポート拡張
方法 : デザイン モードコントロール外観動作拡張する

TemplateDefinition コンストラクタ (ControlDesigner, String, Object, String, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したデザイナテンプレート名、テンプレートプロパティ名を使用して、さらに、テンプレート コンテンツWeb サーバー コントロール限定するかどうか指定して、TemplateDefinition クラス新しインスタンス作成します

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Sub New ( _
    designer As ControlDesigner, _
    name As String, _
    templatedObject As Object, _
    templatePropertyName As String, _
    serverControlsOnly As Boolean _
)
Dim designer As ControlDesigner
Dim name As String
Dim templatedObject As Object
Dim templatePropertyName As String
Dim serverControlsOnly As Boolean

Dim instance As New TemplateDefinition(designer,
 name, templatedObject, templatePropertyName, serverControlsOnly)
public TemplateDefinition (
    ControlDesigner designer,
    string name,
    Object templatedObject,
    string templatePropertyName,
    bool serverControlsOnly
)
public:
TemplateDefinition (
    ControlDesigner^ designer, 
    String^ name, 
    Object^ templatedObject, 
    String^ templatePropertyName, 
    bool serverControlsOnly
)
public TemplateDefinition (
    ControlDesigner designer, 
    String name, 
    Object templatedObject, 
    String templatePropertyName, 
    boolean serverControlsOnly
)
public function TemplateDefinition (
    designer : ControlDesigner, 
    name : String, 
    templatedObject : Object, 
    templatePropertyName : String, 
    serverControlsOnly : boolean
)

パラメータ

designer

親 ControlDesigner オブジェクト

name

テンプレートの名前。

templatedObject

テンプレート格納するオブジェクト

templatePropertyName

デザイン ホストプロパティ リストでこのテンプレートを表すプロパティ名。

serverControlsOnly

テンプレート コンテンツWeb サーバー コントロールのみを許可するかどうかを示すブール値。

例外例外
例外種類条件

ArgumentNullException

designernull 参照 (Visual Basic では Nothing) です。

または

templatedObjectnull 参照 (Visual Basic では Nothing) です。

.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TemplateDefinition コンストラクタ (ControlDesigner, String, Object, String, Style)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したデザイナテンプレート名、テンプレートプロパティ名、および Style オブジェクト使用して、TemplateDefinition クラス新しインスタンス作成します

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Sub New ( _
    designer As ControlDesigner, _
    name As String, _
    templatedObject As Object, _
    templatePropertyName As String, _
    style As Style _
)
Dim designer As ControlDesigner
Dim name As String
Dim templatedObject As Object
Dim templatePropertyName As String
Dim style As Style

Dim instance As New TemplateDefinition(designer,
 name, templatedObject, templatePropertyName, style)
public TemplateDefinition (
    ControlDesigner designer,
    string name,
    Object templatedObject,
    string templatePropertyName,
    Style style
)
public:
TemplateDefinition (
    ControlDesigner^ designer, 
    String^ name, 
    Object^ templatedObject, 
    String^ templatePropertyName, 
    Style^ style
)
public TemplateDefinition (
    ControlDesigner designer, 
    String name, 
    Object templatedObject, 
    String templatePropertyName, 
    Style style
)
public function TemplateDefinition (
    designer : ControlDesigner, 
    name : String, 
    templatedObject : Object, 
    templatePropertyName : String, 
    style : Style
)

パラメータ

designer

親 ControlDesigner オブジェクト

name

テンプレートの名前。

templatedObject

テンプレート格納するオブジェクト

templatePropertyName

デザイン ホストプロパティ リストでこのテンプレートを表すプロパティ名。

style

テンプレート適用する Style オブジェクト

例外例外
例外種類条件

ArgumentNullException

designernull 参照 (Visual Basic では Nothing) です。

または

templatedObjectnull 参照 (Visual Basic では Nothing) です。

.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TemplateDefinition コンストラクタ (ControlDesigner, String, Object, String, Style, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したデザイナテンプレート名、テンプレートプロパティ名、Style オブジェクト使用して、さらに、コンテンツWeb サーバー コントロール限定するかどうか指定して、TemplateDefinition クラス新しインスタンス作成します

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Sub New ( _
    designer As ControlDesigner, _
    name As String, _
    templatedObject As Object, _
    templatePropertyName As String, _
    style As Style, _
    serverControlsOnly As Boolean _
)
Dim designer As ControlDesigner
Dim name As String
Dim templatedObject As Object
Dim templatePropertyName As String
Dim style As Style
Dim serverControlsOnly As Boolean

Dim instance As New TemplateDefinition(designer,
 name, templatedObject, templatePropertyName, style, serverControlsOnly)
public TemplateDefinition (
    ControlDesigner designer,
    string name,
    Object templatedObject,
    string templatePropertyName,
    Style style,
    bool serverControlsOnly
)
public:
TemplateDefinition (
    ControlDesigner^ designer, 
    String^ name, 
    Object^ templatedObject, 
    String^ templatePropertyName, 
    Style^ style, 
    bool serverControlsOnly
)
public TemplateDefinition (
    ControlDesigner designer, 
    String name, 
    Object templatedObject, 
    String templatePropertyName, 
    Style style, 
    boolean serverControlsOnly
)
public function TemplateDefinition (
    designer : ControlDesigner, 
    name : String, 
    templatedObject : Object, 
    templatePropertyName : String, 
    style : Style, 
    serverControlsOnly : boolean
)

パラメータ

designer

親 ControlDesigner オブジェクト

name

テンプレートの名前。

templatedObject

テンプレート格納するオブジェクト

templatePropertyName

デザイン ホストプロパティ リストでこのテンプレートを表すプロパティ名。

style

テンプレート適用する Style オブジェクト

serverControlsOnly

テンプレート コンテンツWeb サーバー コントロール限定するかどうかを示すブール値。

例外例外
例外種類条件

ArgumentNullException

designernull 参照 (Visual Basic では Nothing) です。

または

templatedObjectnull 参照 (Visual Basic では Nothing) です。

.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TemplateDefinition コンストラクタ

TemplateDefinition クラス新しインスタンス作成します。 TemplatedControlDesigner デザインサポート拡張 方法 : デザイン モードコントロール外観動作拡張する
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

TemplateDefinition クラス
TemplateDefinition メンバ
System.Web.UI.Design 名前空間
TemplatedControlDesigner クラス
TemplatedControlDesigner クラス

その他の技術情報

デザインサポート拡張
方法 : デザイン モードコントロール外観動作拡張する
デザインサポート拡張
方法 : デザイン モードコントロール外観動作拡張する

TemplateDefinition コンストラクタ (ControlDesigner, String, Object, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したデザイナテンプレート名、テンプレート、およびプロパティ名を使用して、TemplateDefinition クラス新しインスタンス作成します

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Sub New ( _
    designer As ControlDesigner, _
    name As String, _
    templatedObject As Object, _
    templatePropertyName As String _
)
Dim designer As ControlDesigner
Dim name As String
Dim templatedObject As Object
Dim templatePropertyName As String

Dim instance As New TemplateDefinition(designer,
 name, templatedObject, templatePropertyName)
public TemplateDefinition (
    ControlDesigner designer,
    string name,
    Object templatedObject,
    string templatePropertyName
)
public:
TemplateDefinition (
    ControlDesigner^ designer, 
    String^ name, 
    Object^ templatedObject, 
    String^ templatePropertyName
)
public TemplateDefinition (
    ControlDesigner designer, 
    String name, 
    Object templatedObject, 
    String templatePropertyName
)
public function TemplateDefinition (
    designer : ControlDesigner, 
    name : String, 
    templatedObject : Object, 
    templatePropertyName : String
)

パラメータ

designer

親 ControlDesigner オブジェクト

name

テンプレートの名前。

templatedObject

テンプレート格納するオブジェクト

templatePropertyName

デザイン ホストプロパティ リストでこのテンプレートを表すプロパティ名。

例外例外
例外種類条件

ArgumentNullException

designernull 参照 (Visual Basic では Nothing) です。

または

templatedObjectnull 参照 (Visual Basic では Nothing) です。

.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TemplateDefinition プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

TemplateDefinition クラス
System.Web.UI.Design 名前空間
ControlDesigner クラス
ControlDesigner.TemplateGroups プロパティ
TemplatedControlDesigner クラス

その他の技術情報

デザインサポート拡張
方法 : デザイン モードコントロール外観動作拡張する

TemplateDefinition メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TemplateDefinition クラス
System.Web.UI.Design 名前空間
ControlDesigner クラス
ControlDesigner.TemplateGroups プロパティ
TemplatedControlDesigner クラス

その他の技術情報

デザインサポート拡張
方法 : デザイン モードコントロール外観動作拡張する

TemplateDefinition メンバ

デザイン時に Web サーバー コントロールテンプレート要素定義するプロパティおよびメソッド提供します

TemplateDefinition データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド TemplateDefinition オーバーロードされます。 TemplateDefinition クラス新しインスタンス作成します
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TemplateDefinition クラス
System.Web.UI.Design 名前空間
ControlDesigner クラス
ControlDesigner.TemplateGroups プロパティ
TemplatedControlDesigner クラス

その他の技術情報

デザインサポート拡張
方法 : デザイン モードコントロール外観動作拡張する



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TemplateDefinition」の関連用語

TemplateDefinitionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TemplateDefinitionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS