TemplateGroup Class
A collection of TemplateDefinition objects representing the template elements in a Web server control at design time.
Assembly: System.Design (in System.Design.dll)
The TemplateGroup type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | TemplateGroup(String) | Initializes a new instance of the TemplateGroup class, using the provided name. |
![]() | TemplateGroup(String, Style) | Initializes a new instance of the TemplateGroup class, using the provided name and style. |
| Name | Description | |
|---|---|---|
![]() | GroupName | Gets the name of the group. |
![]() | GroupStyle | Gets the current style for the group. |
![]() | IsEmpty | Gets a value indicating whether there are any templates in the group. |
![]() | Templates | Gets an array of all template definitions in the group. |
| Name | Description | |
|---|---|---|
![]() | AddTemplateDefinition | Adds the provided TemplateDefinition to the group. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The following code example demonstrates how to create a control designer class that derives from the ControlDesigner class. This control designer supports a control with four possible templates.
To try it, compile the code, and then, in a design host such as Visual Studio 2005, look at the page in Design view. Select the control, click the action list to select a template to modify, and then use the drag-and-drop feature to move controls into the template.
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; } } } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
