TemplateGroupCollection 類別

定義

代表控制項設計工具中的 TemplateGroup 物件集合。 此類別無法獲得繼承。

public ref class TemplateGroupCollection sealed : System::Collections::IList
public sealed class TemplateGroupCollection : System.Collections.IList
type TemplateGroupCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public NotInheritable Class TemplateGroupCollection
Implements IList
繼承
TemplateGroupCollection
實作

範例

下列程式碼範例示範如何定義衍生自 類別的 ControlDesigner 簡單控制項設計工具。 衍生控制項設計工具會取得為基類定義的範本群組,以及新增衍生控制項設計工具專屬的範本群組,以實 TemplateGroups 作 屬性。

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

namespace Examples.AspNet
{
    // Define a simple control designer that adds a
    // template group to the template group collection.
    class DerivedControlDesigner : System.Web.UI.Design.ControlDesigner
    {
        private DerivedControl internalControl = null;

        private const String templateGroupName = "My template group";
        private const String templateDefinitionName1 = "First";
        private const String templateDefinitionName2 = "Second";
        private TemplateGroup internalGroup = null;

        // Override the read-only TemplateGroups property.
        // Get the base group collection, and add a group 
        // with two template definitions for the derived
        // control designer.
        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                // Start with the groups defined by the base designer class.
                TemplateGroupCollection groups = base.TemplateGroups;

                if (internalGroup == null) 
                {
                    // Define a new group with two template definitions.
                    internalGroup = new TemplateGroup(templateGroupName, 
                                                internalControl.ControlStyle);

                    TemplateDefinition templateDef1 = new TemplateDefinition(this, 
                        templateDefinitionName1, internalControl, 
                        templateDefinitionName1, internalControl.ControlStyle);

                    TemplateDefinition templateDef2 = new TemplateDefinition(this, 
                        templateDefinitionName2, internalControl, 
                        templateDefinitionName2, internalControl.ControlStyle);

                    internalGroup.AddTemplateDefinition(templateDef1);
                    internalGroup.AddTemplateDefinition(templateDef2);
                }

                // Add the new template group to the collection.
                groups.Add(internalGroup);

                return groups;
            }
        }
    }

    // Define a simple web control, and associate it with the designer.
    [DesignerAttribute(typeof(DerivedControlDesigner),
                       typeof(IDesigner))]
    public class DerivedControl : WebControl
    {
        // Define derived control behavior here.
    }
}
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.ComponentModel
Imports System.ComponentModel.Design

Namespace Examples.AspNet

    ' Define a simple control designer that adds a
    ' template group to the template group collection.
    Class DerivedControlDesigner
        Inherits System.Web.UI.Design.ControlDesigner

        Private Dim internalControl As DerivedControl = Nothing
    
        Private Const templateGroupName As String = "My template group"
        Private Const templateDefinitionName1 As String = "First"
        Private Const templateDefinitionName2 As String = "Second"
        Private Dim internalGroup As TemplateGroup = Nothing

        ' Override the read-only TemplateGroups property.
        ' Get the base group collection, and add a group 
        ' with two template definitions for the derived
        ' control designer.
        Public Overrides ReadOnly Property TemplateGroups As TemplateGroupCollection
            Get

                ' Start with the groups defined by the base designer class.
                Dim groups As TemplateGroupCollection  = MyBase.TemplateGroups

                If internalGroup Is Nothing

                    ' Define a new group with two template definitions.
                    internalGroup = New TemplateGroup(templateGroupName, _
                                                internalControl.ControlStyle)

                    Dim templateDef1 As TemplateDefinition = new TemplateDefinition(Me, _
                        templateDefinitionName1, internalControl, _
                        templateDefinitionName1, internalControl.ControlStyle)

                    Dim templateDef2 As TemplateDefinition = new TemplateDefinition(Me, _
                        templateDefinitionName2, internalControl, _
                        templateDefinitionName2, internalControl.ControlStyle)

                    internalGroup.AddTemplateDefinition(templateDef1)
                    internalGroup.AddTemplateDefinition(templateDef2)

                End If

                ' Add the new template group to the collection.
                groups.Add(internalGroup)

                return groups
            End Get
        End Property

    End Class

    ' Simple Web control, derived from the Web control class.
    <DesignerAttribute(GetType(DerivedControlDesigner), GetType(IDesigner))> _
    Public Class DerivedControl
        Inherits WebControl
        
        ' Define derived control behavior here.
    End Class

End Namespace

備註

類別 ControlDesigner 和任何衍生類別,會將 TemplateGroups 屬性 TemplateGroupCollection 定義為 物件。 屬性 TemplateGroupCollection 通常僅供設計主機使用,例如 Visual Studio 2005。

當加入物件時,集合會動態增加大小。 這個集合中的索引是以零起始。 Count使用 屬性來判斷集合中的群組數目。

此外,請使用 TemplateGroupCollection 方法和屬性來提供下列功能:

  • Add 單一群組新增至集合的方法。

  • Insert在集合內特定索引處加入群組的方法。

  • Remove移除群組的方法。

  • RemoveAt要移除特定索引之群組的方法。

  • Contains判斷特定群組是否已經在集合中的方法。

  • IndexOf 取集合內群組索引的方法。

  • 使用 Item[] 陣列標記法,在特定索引取得或設定群組的索引子。

  • AddRange 多個群組新增至集合的方法。

    您可以將多個群組新增為群組陣列,或是透過另一個 TemplateGroupCollection 控制項設計工具的 屬性擷取 TemplateGroups 的物件。

  • Clear從集合中移除所有群組的方法。

建構函式

TemplateGroupCollection()

初始化 TemplateGroupCollection 類別的新執行個體。

屬性

Count

取得集合中 TemplateGroup 物件的數目。

Item[Int32]

取得或設定位於集合中指定索引上的 TemplateGroup 物件。

方法

Add(TemplateGroup)

將指定的 TemplateGroup 物件加入至集合的尾端。

AddRange(TemplateGroupCollection)

將現有 TemplateGroupCollection 物件中的樣板群組加入至目前的 TemplateGroupCollection 物件。

Clear()

移除集合中所有的群組。

Contains(TemplateGroup)

判斷集合中是否包含指定的群組。

CopyTo(TemplateGroup[], Int32)

將集合中的群組複製到相容的一維陣列,從目標陣列的指定索引處開始。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IndexOf(TemplateGroup)

傳回指定的 TemplateGroup 物件在集合中的索引。

Insert(Int32, TemplateGroup)

TemplateGroup 插入位於指定索引的集合。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Remove(TemplateGroup)

從集合中移除指定的 TemplateGroup 物件。

RemoveAt(Int32)

移除位於集合中指定索引上的 TemplateGroup 物件。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ICollection.CopyTo(Array, Int32)

如需這個成員的說明,請參閱 CopyTo(Array, Int32)

ICollection.Count

如需這個成員的說明,請參閱 Count

ICollection.IsSynchronized

如需這個成員的說明,請參閱 IsSynchronized

ICollection.SyncRoot

如需這個成員的說明,請參閱 SyncRoot

IEnumerable.GetEnumerator()

如需這個成員的說明,請參閱 GetEnumerator()

IList.Add(Object)

如需這個成員的說明,請參閱 Add(Object)

IList.Clear()

如需這個成員的說明,請參閱 Clear()

IList.Contains(Object)

如需這個成員的說明,請參閱 Contains(Object)

IList.IndexOf(Object)

如需這個成員的說明,請參閱 IndexOf(Object)

IList.Insert(Int32, Object)

如需這個成員的說明,請參閱 Insert(Int32, Object)

IList.IsFixedSize

如需這個成員的說明,請參閱 IsFixedSize

IList.IsReadOnly

如需這個成員的說明,請參閱 IsReadOnly

IList.Item[Int32]

如需這個成員的說明,請參閱 IList 類別。

IList.Remove(Object)

如需這個成員的說明,請參閱 Remove(Object)

IList.RemoveAt(Int32)

如需這個成員的說明,請參閱 RemoveAt(Int32)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱