.NET Framework Design-Time Architecture


In the .NET Framework, designable components participate in a rich and extensible design-time architecture to create a rapid application development (RAD) experience for the page developer. As we described in Chapter 3, "Component Programming Overview," a designable component is a class that implements the IComponent interface or derives directly or indirectly from the System.ComponentModel.Component class that implements this interface. For brevity, in this chapter we will use component in place of designable component when no ambiguity comes of using the shorter term . Because the base Control class implements IComponent , all server controls are designable components and automatically participate in the design-time architecture of the .NET Framework.

An important aspect of the .NET design-time architecture is that you do not implement design-time capabilities within your control but implement those capabilities in classes outside your control. You then associate those classes with your control via metadata attributes. This separation of the design-time implementation from the run-time implementation makes the design-time architecture flexible and extensible. It also prevents the design-time functionality from impacting your control's run-time behavior.

Four main categories of classes provide advanced design-time functionality:

  • Type converter

    A class that is associated with a type or a property and performs string-to-value conversions as well as conversions between the type it is associated with and other types. The property browser uses type converters to display property values as text strings and to convert user -entered text strings into objects that represent the values of properties. The designer also uses type converters for other tasks , which we will describe in the "Type Converters" section in this chapter. We examined type converters and showed how to implement them for custom types in Chapter 10, "Complex Properties and State Management."

  • Designer

    A class associated with a control that governs the appearance and behavior of the control on the design surface. A designer enables a control to provide a different visual representation at design time than at run time. For example, the DataList control uses a designer class to offer WYSIWIG template editing. We'll show you how to implement designers in the "Designers" section of this chapter. Note that, in this context, the term designer has a different meaning than the term visual designer , which refers to the visual design environment.

  • UI type editor

    A class that is associated with a type or a property and provides a specialized user interface for editing a property. A UI type editor is launched from the property browser and is useful when the simple text entry UI provided by the property browser is not adequate for editing a property. For example, the color picker drop-down list within the property grid that enables a page developer to select a color for the BackColor or ForeColor property of a Web control in a WYSIWYG fashion is a UI type editor. We'll show you how to implement UI type editors in the "UI Type Editors" section in this chapter.

  • Component editor

    A class associated with a control that provides a UI for editing the properties of a control as a whole. Component editors provide capabilities that are similar to property pages in Microsoft ActiveX controls. A component editor is not a replacement for the property browser but provides a more convenient UI for editing commonly accessed properties of a control. For example, the DataList control is associated with a component editor that is launched when a page developer chooses the Property Builder command from the context menu. We'll show you how to implement a component editor in the "Component Editors" section in this chapter.

Figure 15-1 provides an overview of the design-time architecture of the .NET Framework.

Figure 15-1. The design-time architecture of the .NET Framework

graphics/f15hn01.jpg

Figure 15-1 uses a hypothetical custom Web control named MyControl to demonstrate the relationship between a control and the classes that provide design-time functionality:

  • The System.Drawing.ColorConverter class is a type converter that enables the property browser to display the value of the MyColor property of MyControl as a text string. ColorConverter derives from the System.ComponentModel.TypeConverter class. ColorConverter is associated with the System.Drawing.Color type of the MyColor property via the System.ComponentModel.TypeConverterAttribute metadata attribute. Type converters are indirectly associated with a control through the control's property types.

  • The MyControlDesigner class is a designer that governs the appearance and behavior of the MyControl control on the design surface. MyControlDesigner derives from System.Web.UI.Design.ControlDesigner and is associated with MyControl via the System.ComponentModel.DesignerAttribute metadata attribute.

  • The System.Drawing.Design.ColorEditor class is a UI type editor that enables the property browser to offer a special UI in the form of a color picker drop-down list when a page developer clicks the MyColor property in the property browser. ColorEditor derives from the System.Drawing.Design.UITypeEditor class and is associated with the Color type via the System.ComponentModel.EditorAttribute metadata attribute. UI type editors are indirectly associated with a control through the control's property types.

  • The MyControlComponentEditor class is a component editor that provides a UI for editing the frequently accessed properties of MyControl . MyControlComponentEditor derives from System.Windows.Forms.Design.WindowsFormsComponentEditor and is associated with MyControl via the EditorAttribute metadata attribute.

Most of this chapter will be devoted to describing how to implement the classes that provide advanced design-time functionality ”designers, UI type editors, and component editors. These classes in turn utilize design-time services that are provided by a visual design environment, such as the Web Forms designer in Visual Studio .NET. We won't describe how to implement design-time services in this book because these are not implemented by control developers but provided by the design-time environment.

Although we described the design-time architecture in terms of controls, the core architecture shown in Figure 15-1 applies to all designable components. In this figure, if you replace Control with IComponent and replace ControlDesigner with IDesigner , the resulting illustration will represent the more general design-time architecture of the .NET Framework.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net