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和任何派生类将属性定义为TemplateGroupsTemplateGroupCollection对象。 该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

适用于

另请参阅