I’ve been thinking a lot lately on how different types of layout controls can be used make the tools and the framework do the heavy lifting for us in our Silverlight Development. Karl Shifflett recently posted an example creating a custom WPF control to make it easier to layout a data input screen and I decided to build out a Silverlight version.
The control extends an ItemsControl to use a custom container that provides a text label and layout for input controls.
The result is a custom control that allows me to add input controls such as TextBoxes and CheckBoxes and get labels and much of the styling for free. Silverlight’s DataBinding capabilities allow me to set a DataContext for the FormControl, and then simply specify an individual binding for each field.
<TextBox Zelt:FormItem.LabelContent="First Name" Text="{Binding FirstName}" Width="250"/>
<TextBox Zelt:FormItem.LabelContent="Last Name" Text="{Binding LastName}" Width="250"/>
Utilizing this type of markup allows for a lot of potential in tool support. I’m sure that Karl plans to support this type of content in his XAML Power Toys add-in.
I’ve got a few additions before I share out the code, but I’d welcome any feedback on this approach.