Tuesday, December 13, 2005 12:50 AM Emile Bosch

Pimp your winform application with VisualFX Cab ObjectBuilder Extension

Don't you hate it when you present your nice hardworked CAB driven multi layered ultra winform application to your customer, and they respond with an reaction sometwhat like: "I really dont like that color of that textbox there". And then as nice as you are, you pop up the IDE, change the color of textbox only to hear that you have to change now every textbox there is in your application. When you are finally done changing every darn single textbox, the unit manager comes in screaming that the colors dont match with his suit and you have to change it all back again.

Introducing VisualFx CAB Extension
For these kind of situations i have tried to make something that declaratively defines all the colors and styles on your application using an stylesheet kind of XML file. In this XML file you can define a set of properties as an "style", and bind them to controls using "style bindings". Under the hood it uses an custom objectbuilder strategy, which injects the properties every time the object builder executes the BuildUp method. It uses an simple engine to resolve the possible candidate stylebindings for the given injectee.  Lets examine the following file for example:

<VisualFX>
 <StyleDeclarations>
  <Style StyleId="MyStyle">
   <Properties>
    <Property name="ForeColor" value="Navy" />
    <Property name="BackColor" value="LightSkyBlue" />
   </Properties>
  </Style>
 </StyleDeclarations>
 <StyleBindings>
  <!--  Every TextBox should use MyStyle -->
  <Binding ControlPath="." Type="System.Windows.Forms.TextBox" StyleId="MyStyle"/>

 </StyleBindings>
</VisualFX>

This example here would yield that every textbox in your application visited by the ObjectBuilder would have its properties set to "MyStyle" (Which in this case is ForeColor=Navy, and BackColor=LightSkyBlue.
The colors are set by asking for the appropiate type converter by asking for TypeDescriptor.GetConverter();

Style binding criteria
For now there are 2 main criterias in which you can bind you styles to an control:

Bind using an control type criteria
You can bind your styles to any type of control by specifying the Type attribute on the Binding. For instance: Color all controls with the Type = System.Windows.Forms.TextBox blue.
 <Binding ControlPath="." Type="System.Windows.Forms.TextBox" StyleId="MyStyle"/>

Bind using an Control Path criteria
Every control has an name in winforms. You can also assign your controls by specifing its path name. For instance.  Pain the control blue which is the control with the name
"InfoText", which is a child of the control with the name "InfoPanel" which is a  child of "InfoSmartPart" like this:
 <Binding ControlPath="InfoSmartPart.InfoPanel.InfoText" StyleId="MyStyle"/>

And then there is the third option which is actually an combination of those above.

Where to go from here?
The concept is actually quite simple yet powerful. But i know there is much more in it than i can see right now, therefore i would like you to give me lots of input. I already decided to implement the following features in the upcoming releases:

  • Multiple color schemes (Give the Unitmanager his suit matching colors)
  • Personalization (Set the colors in an propertyscreen)
  • IExtenderProvider / TypeDescriptionProvider for visual support and rendering of styles design-time

Im finishing up the intial version, i still have some last minute changes to implement (thanks to some nice tips from my collegue Marc) , so if you have any comments or ideas, let me know.
I will post the initial version somewhere around dec 20 'th.

Filed under:

# re: Pimp your winform application with VisualFX Cab ObjectBuilder Extension

Wednesday, December 14, 2005 12:03 AM by Marc Jacobi

Dont forget to provide support for properties that are a ref-type/class and have properties themselves. Like TextBox.Size.Width or TextBox.Location.X (I just made up the property names). You should be able to handle Control.Property.Property.Property.Property.Property and not crash when any of those is null ;-)

# re: Pimp your winform application with VisualFX Cab ObjectBuilder Extension

Monday, December 19, 2005 4:00 AM by Axel

Ah. But shouldn't it read 'Ritalin driven development' instead of... >:)

Way to go Emile... Enjoyed your Wmi thingy...

Leave a Comment

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