Bewerken

Share via


TemplateGroupCollection Class

Definition

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
Inheritance
TemplateGroupCollection
Implements

Examples

The following code example demonstrates how to define a simple control designer that is derived from the ControlDesigner class. 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

Remarks

The ControlDesigner class, and any derived class, defines the TemplateGroups property as a TemplateGroupCollection object. The TemplateGroupCollection property is typically used only by a design host such as Visual Studio 2005.

The collection dynamically increases in size as objects are added. Indexes in this collection are zero-based. Use the Count property to determine how many groups are in the collection.

Additionally, use the TemplateGroupCollection methods and properties to provide the following functionality:

  • The Add method to add a single group to the collection.

  • The Insert method to add a group at a particular index within the collection.

  • The Remove method to remove a group.

  • The RemoveAt method to remove the group at a particular index.

  • The Contains method to determine whether a particular group is already in the collection.

  • The IndexOf method to retrieve the index of a group within the collection.

  • The Item[] indexer to get or set the group at a particular index, using array notation.

  • The AddRange method to add multiple groups to the collection.

    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.

  • The Clear method to remove all groups from the collection.

Constructors

TemplateGroupCollection()

Initializes a new instance of the TemplateGroupCollection class.

Properties

Count

Gets the number of TemplateGroup objects in the collection.

Item[Int32]

Gets or sets a TemplateGroup object at the specified index in the collection.

Methods

Add(TemplateGroup)

Adds the specified TemplateGroup object to the end of the collection.

AddRange(TemplateGroupCollection)

Adds the template groups in an existing TemplateGroupCollection object to the current TemplateGroupCollection object.

Clear()

Removes all groups from the collection.

Contains(TemplateGroup)

Determines whether the specified group is contained within the collection.

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)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(TemplateGroup)

Returns the index of the specified TemplateGroup object within the collection.

Insert(Int32, TemplateGroup)

Inserts a TemplateGroup object into the collection at the specified index.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TemplateGroup)

Removes the specified TemplateGroup object from the collection.

RemoveAt(Int32)

Removes the TemplateGroup object at the specified index within the collection.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

For a description of this member, see CopyTo(Array, Int32).

ICollection.Count

For a description of this member, see Count.

ICollection.IsSynchronized

For a description of this member, see IsSynchronized.

ICollection.SyncRoot

For a description of this member, see SyncRoot.

IEnumerable.GetEnumerator()

For a description of this member, see GetEnumerator().

IList.Add(Object)

For a description of this member, see Add(Object).

IList.Clear()

For a description of this member, see Clear().

IList.Contains(Object)

For a description of this member, see Contains(Object).

IList.IndexOf(Object)

For a description of this member, see IndexOf(Object).

IList.Insert(Int32, Object)

For a description of this member, see Insert(Int32, Object).

IList.IsFixedSize

For a description of this member, see IsFixedSize.

IList.IsReadOnly

For a description of this member, see IsReadOnly.

IList.Item[Int32]

For a description of this member, see the IList class.

IList.Remove(Object)

For a description of this member, see Remove(Object).

IList.RemoveAt(Int32)

For a description of this member, see RemoveAt(Int32).

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also