Updating Component properties in the designer

Published Sunday, July 16, 2006 11:17 PM

I have been working on a set of custom ASP.NET controls that offer specific design time experience for a client. Part of that is to make some existing controls very designer friendly. Apart from some custom rendering, I have been adding SmartTag support to the control to enhance the design time experience. For those unaware, a good example of a SmartTag (or ActionList in coding terms) is shown below:

Smart Tag Example

So I wanted to add SmartTag support which showed some customised options for this particular control. The way you do this is via custom ActionLists.

When you create a component, you can attach a specific Designer to the component to customise the designer/design time experience of the component using a simple attribute on the component class like:

[Designer(typeof(CustomPanelDesigner))]
public class TestCustomPanel : Panel
{
  . . . . .

 

To attach a custom SmartTag menu, you need to define a custom ActionList within the custom designer class as shown in the following code:

public override System.ComponentModel.Design.DesignerActionItemCollection GetSortedActionItems()
{
  DesignerActionItemCollection coll =
new DesignerActionItemCollection();
  coll.Add(
new DesignerActionHeaderItem("Appearance"));
  coll.Add(
new DesignerActionPropertyItem("FormStyle", "Form CSS Style","Appearance"));
  return coll;
}

Now all this is well and good, and you can glean this from the documentation. What I found challenging was trying to update a property on the component being designed -AND- have that change reflected in the property window of the designer as well as persisted in the markup for the control within the page.

After much searching, and in the ed, reflecting over ASP.NEt controls, its this single statement which does the trick:

TypeDescriptor.GetProperties(this.relatedDesigner.Component)["YourPropertyToSet"].SetValue(this.relatedDesigner.Component, "your property new value");

Hopefully, thats usefull to somebody.

Comments

# Brian Morearty said on Sunday, January 7, 2007 2:09 AM

Yes!!

Thanks for publishing the one bit of info on custom designers that I couldn't find anywhere else.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

Syndication