For each template,
we create a new TemplateDefinition, provide it a name, and add it to the TemplateGroupCollection
object that is returned at the end of method.
Listing 11-14 provides the full source for TemplateMenuDesigner.
Listing 11-14. The TemplateMenuDesigner Source
using System;
using System.ComponentModel;
using System.Web.UI.Design;
using ControlsBook2Lib.Ch06;
namespace ControlsBook2Lib.Ch11.Design
{
public class TemplateMenuDesigner : ControlDesigner
{
TemplateGroupCollection templateGroupCol = null;
public override void Initialize(IComponent component)
{
base.Initialize(component);
if (!(component is TemplateMenu))
{
throw new ArgumentException(
"Component must be a TemplateMenu control for this custom designer."
, "component");
}
else
{
SetViewFlags(ViewFlags.TemplateEditing, true);
}
}
public override TemplateGroupCollection TemplateGroups
{
get
{
if (templateGroupCol == null)
{
// Get the base collection
templateGroupCol = base.TemplateGroups;
TemplateGroup templateGroup;
TemplateDefinition templateDef;
TemplateMenu ctl;
CHAPTER 11 ?– DES IGN-TIME S UPPORT 567
//Get reference to the component as TemplateMenu
ctl = (TemplateMenu)Component;
//Create Template Group
templateGroup = new TemplateGroup("TemplateMenu Templates");
//Header
templateDef = new TemplateDefinition(this, "Header",
ctl, "HeaderTemplate", false);
templateGroup.
Pages:
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741