Recently, at work I was assigned to create a way to allow users to generate custom fields in order to customize out application. The customer should be allowed to add as many fields as he wants as well as validation for the field and be able to search on the field. The database for this is fairly simple. The Windows Forms User Interface is the hard part.
In the UI, I decided to use tabs. There are a set of predefined tabs that ship with the application and additional tabs can be added by the customer. On these tabs the customer can layout the controls he wants to use. I decided to host the designer to gain all the benefits of aligning controls and such. Initially the user will only have 5 controls: Label, Textbox, ComboBox, DateTimePicker, MaskedTextBox () and validators: .
Now that the user has laid out the tab I want to easily store this and retrieve it from the database. I’ll will have to tell you that I am vehemently against storing binary blobs in the database. So I started looking from a way to store a Windows Form as XML. I found a few different ways. I had used SVG in the past for another project at work, but that is not specific to Windows Forms or UIs. The first I ran across was WML. I actually went to the expert DonXML to get his opinion on XML based UIs. Here Don compares SVG with Avalon. Avalon is a “pillar” of Longhorn – the next version of Windows. It is a UI framework mostly based on XAML Here are some good articles on Avalon & XAML:
http://www.joemarini.com/tutorials/tutorialpages/xamlblogexplorer.php
http://msdn.microsoft.com/longhorn/default.aspx?pull=/library/en-us/dnavalon/html/avalon03262004.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnavalon/html/avalon01062004.asp
http://www.xaml.net/
XAML, a Microsoft standard, seemed to be the answer to my problem. But I can’t wait until .NET 2.0 or Longhorn release. So I found 2 XAML implementations that work with .NET 1.1:
http://www.xamalon.com/
http://www.myxaml.com/
Xamalon is in Beta and will require a license fee. MyXAML is Open Source and seemed like the way to go. So I am now storing windows forms in a database as XML. There are only 2 caveats:
1. Neither library allows you to operate on anything other than a Form. I just wanted a user control. No big deal just wasn’t what I was expecting.
2. There are very few examples / illustrations of saving a form as XML. Most things I have seen go the other way. Create an XML document and then the form pops out. I want to create the form and “serialize” it as XAML. MyXAML does show how to do this but you have to dig around for it.