TemplateGroupCollection TemplateGroupCollection TemplateGroupCollection TemplateGroupCollection Class

定义

表示控件设计器内的 TemplateGroup 对象的集合。Represents a collection of TemplateGroup objects within a control designer. 此类不能被继承。This class cannot be inherited.

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
继承
TemplateGroupCollectionTemplateGroupCollectionTemplateGroupCollectionTemplateGroupCollection
实现

示例

下面的代码示例演示如何定义派生自ControlDesigner类的简单控件设计器。The following code example demonstrates how to define a simple control designer that is derived from the ControlDesigner class. 派生的控件设计器通过TemplateGroups获取为基类定义的模板组并添加特定于派生控件设计器的模板组来实现属性。The derived control designer implements the TemplateGroups property by getting the template groups that are defined for the base class and adding a template group that is specific to the derived control designer.

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

注解

类和任何派生类都将TemplateGroups属性定义为TemplateGroupCollection对象。 ControlDesignerThe ControlDesigner class, and any derived class, defines the TemplateGroups property as a TemplateGroupCollection object. 属性通常仅由设计宿主 (如) Visual Studio 2005Visual Studio 2005使用。 TemplateGroupCollectionThe TemplateGroupCollection property is typically used only by a design host such as Visual Studio 2005Visual Studio 2005.

添加对象时, 集合的大小动态增加。The collection dynamically increases in size as objects are added. 此集合中的索引从零开始。Indexes in this collection are zero-based. Count使用属性来确定集合中有多少个组。Use the Count property to determine how many groups are in the collection.

此外, 使用TemplateGroupCollection方法和属性提供以下功能:Additionally, use the TemplateGroupCollection methods and properties to provide the following functionality:

  • 用于Add将单个组添加到集合中的方法。The Add method to add a single group to the collection.

  • 用于Insert将组添加到集合中特定索引处的方法。The Insert method to add a group at a particular index within the collection.

  • 用于Remove移除组的方法。The Remove method to remove a group.

  • 用于移除特定索引处的组的方法。RemoveAtThe RemoveAt method to remove the group at a particular index.

  • 用于确定特定组是否已存在于集合中的方法。ContainsThe Contains method to determine whether a particular group is already in the collection.

  • 用于检索集合中组的索引的方法。IndexOfThe IndexOf method to retrieve the index of a group within the collection.

  • 用于获取或设置特定索引处的组的索引器,使用数组表示法。Item[Int32]The Item[Int32] indexer to get or set the group at a particular index, using array notation.

  • AddRange集合中添加多个组的方法。The AddRange method to add multiple groups to the collection.

    可以将多个组添加为组的数组, 或添加为TemplateGroupCollection通过其他控件设计器的TemplateGroups属性检索的对象。You can add multiple groups either as an array of groups or as a TemplateGroupCollection object that you retrieve through the TemplateGroups property of another control designer.

  • Clear从集合中移除所有组的方法。The Clear method to remove all groups from the collection.

构造函数

TemplateGroupCollection() TemplateGroupCollection() TemplateGroupCollection() TemplateGroupCollection()

初始化 TemplateGroupCollection 类的新实例。Initializes a new instance of the TemplateGroupCollection class.

属性

Count Count Count Count

获取集合中 TemplateGroup 对象的数量。Gets the number of TemplateGroup objects in the collection.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

获取或设置集合中指定索引处的 TemplateGroup 对象。Gets or sets a TemplateGroup object at the specified index in the collection.

方法

Add(TemplateGroup) Add(TemplateGroup) Add(TemplateGroup) Add(TemplateGroup)

将指定的 TemplateGroup 对象添加到集合末尾。Adds the specified TemplateGroup object to the end of the collection.

AddRange(TemplateGroupCollection) AddRange(TemplateGroupCollection) AddRange(TemplateGroupCollection) AddRange(TemplateGroupCollection)

将现有 TemplateGroupCollection 对象中的模板组添加到当前 TemplateGroupCollection 对象。Adds the template groups in an existing TemplateGroupCollection object to the current TemplateGroupCollection object.

Clear() Clear() Clear() Clear()

从集合中移除所有组。Removes all groups from the collection.

Contains(TemplateGroup) Contains(TemplateGroup) Contains(TemplateGroup) Contains(TemplateGroup)

确定指定组是否包含在集合中。Determines whether the specified group is contained within the collection.

CopyTo(TemplateGroup[], Int32) CopyTo(TemplateGroup[], Int32) CopyTo(TemplateGroup[], Int32) CopyTo(TemplateGroup[], Int32)

将集合中的组复制到一个兼容的一维数组(从目标数组的指定索引处开始)。Copies the groups in the collection to a compatible one-dimensional array, starting at the specified index of the target array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(TemplateGroup) IndexOf(TemplateGroup) IndexOf(TemplateGroup) IndexOf(TemplateGroup)

返回指定的 TemplateGroup 对象在集合中的索引。Returns the index of the specified TemplateGroup object within the collection.

Insert(Int32, TemplateGroup) Insert(Int32, TemplateGroup) Insert(Int32, TemplateGroup) Insert(Int32, TemplateGroup)

TemplateGroup 对象插入到集合中的指定索引处。Inserts a TemplateGroup object into the collection at the specified index.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TemplateGroup) Remove(TemplateGroup) Remove(TemplateGroup) Remove(TemplateGroup)

从集合中移除指定的 TemplateGroup 对象。Removes the specified TemplateGroup object from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

移除集合中指定索引处的 TemplateGroup 对象。Removes the TemplateGroup object at the specified index within the collection.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

有关此成员的说明,请参见 CopyTo(Array, Int32)For a description of this member, see CopyTo(Array, Int32).

ICollection.Count ICollection.Count ICollection.Count ICollection.Count

有关此成员的说明,请参见 CountFor a description of this member, see Count.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

有关此成员的说明,请参见 IsSynchronizedFor a description of this member, see IsSynchronized.

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

有关此成员的说明,请参见 SyncRootFor a description of this member, see SyncRoot.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

有关此成员的说明,请参见 GetEnumerator()For a description of this member, see GetEnumerator().

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

有关此成员的说明,请参见 Add(Object)For a description of this member, see Add(Object).

IList.Clear() IList.Clear() IList.Clear() IList.Clear()

有关此成员的说明,请参见 Clear()For a description of this member, see Clear().

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

有关此成员的说明,请参见 Contains(Object)For a description of this member, see Contains(Object).

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

有关此成员的说明,请参见 IndexOf(Object)For a description of this member, see IndexOf(Object).

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

有关此成员的说明,请参见 Insert(Int32, Object)For a description of this member, see Insert(Int32, Object).

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

有关此成员的说明,请参见 IsFixedSizeFor a description of this member, see IsFixedSize.

IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

有关此成员的说明,请参见 IsReadOnlyFor a description of this member, see IsReadOnly.

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

有关此成员的说明,请参见 IList 类。For a description of this member, see the IList class.

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

有关此成员的说明,请参见 Remove(Object)For a description of this member, see Remove(Object).

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

有关此成员的说明,请参见 RemoveAt(Int32)For a description of this member, see RemoveAt(Int32).

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅