DesignerAttribute


DesignerAttribute

To associate a designer with your control, you must apply the System.ComponentModel.DesignerAttribute metadata attribute to the control. The constructor of the DesignerAttribute is overloaded. The two “parameter overloads take the type of the designer as their second argument. The default value of the second parameter, the IDesigner interface type, is valid for most common scenarios. Therefore, in this chapter, we will describe the one “parameter overloads only.

The attribute usage syntax depends on the assembly location of the designer relative to the assembly location of the control with which it is associated. When the control and its designer are deployed in the same assembly, the constructor of DesignerAttribute can take an early-bound type reference to the designer, as shown in the following example:

 [ Designer(typeof(MSPress.ServerControls.Design.ContactInfoDesigner)) ] publicclassContactInfo:WebControl,INamingContainer{...} 

If the namespace that contains the designer is referenced with a using statement in the control, you can pass in the shorter class name of the designer in the constructor.

You can also use the early-bound syntax when the designer is a built-in class in the .NET Framework. For example, you can associate the ReadWriteControlDesigner class with a MyControl class deployed in a private assembly by using this syntax:

 usingSystem.Web.UI.Design; [ Designer(typeof(ReadWriteControlDesigner)) ] publicclassMyControl:WebControl{...} 

If the control and its designer are deployed in different assemblies and the designer is not a built-in class in the .NET Framework, the compiler cannot resolve an early-bound type reference to the designer because the reference creates a circular dependency between the two assemblies. Therefore, you must provide a late-bound reference to the designer ”that is, a reference that is resolved at design time. A late-bound type reference is an assembly qualified type name , which is represented as a String that contains the full type name and the full assembly name. (We'll show examples of assembly qualified type names in a moment.) In this case, you must use the overload of the DesignerAttribute constructor that accepts a String argument for the type reference.

When the designer is in a private assembly, the full assembly name is merely the name of the assembly, as shown by the second part of the string argument in the following example:

 [ Designer("MSPress.ServerControls.Design.ContactInfoDesigner, " +  "MSPress.ServerControls.Design") ] publicclassContactInfo:WebControl,INamingContainer{...} 

In this example, we assume that ContactInfoDesigner is deployed in the hypothetical MSPress.ServerControls.Design private assembly, whereas ContactInfo is deployed in the MSPress.ServerControls private assembly.

When the designer exists in a shared assembly in the GAC, the full name of the assembly includes the name, version, culture, and public key token of the assembly, as shown by the second part of the string argument in the following example:

 [ Designer("System.Web.UI.Design.ReadWriteControlDesigner, " +  "System.Design,Version=1.0.3300.0,Culture=neutral, " +  "PublicKeyToken=b03f5f7f11d50a3a") ] publicclassMyControl:WebControl{...} 

Chapter 17 describes shared assemblies and full assembly names in greater detail.



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