Geeks With Blogs
Marcin Celej blog

In application I write actually there is a requirement that end-user should have ability to change the UI look. My strange-user can design ui elements on each form and user control in the application. He also 'needs' to add new controls to the UI. Let's not discuss sense of the requirement as I don't like it anyway. I didn't implement the feature yet but I found in the MSDN Magazine an artcile about hosting VS designers in .NET application (The Perfect Host: Create And Host Custom Designers With The .NET Framework 2.0). There is also great sample (amazingly simple) that shows how to create application that mimics VS designer behavior (toolbox, generated code viewing, designer surface, property grid, etc.)

In the host application I created a Form (dragged some controls on the Form designer surface from the toolbox):

Then I saved the designed Form to xml (I could save it to .cs file, as the VS does, but I am interested not in application recompilation but in runtime enhancement. In such case saving my forms to xml suits me better). The Form serialized to xml looks like this:

  <Object type="System.Windows.Forms.Form" name="Form1" children="Controls">
    <Object type="System.Windows.Forms.TextBox" name="TextBox1" children="Controls">
      <Property name="Location">62, 6</Property>
      <Property name="Size">100, 20</Property>
      <Property name="DataBindings">
        <Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
      </Property>
      <Property name="Name">TextBox1</Property>
      <Property name="Text">Marcin Celej</Property>
      <Property name="TabIndex">1</Property>
    </Object>
    <Object type="System.Windows.Forms.Label" name="Label1" children="Controls">
      <Property name="TabIndex">0</Property>
      <Property name="Size">68, 23</Property>
      <Property name="Name">Label1</Property>
      <Property name="Text">Name:</Property>
      <Property name="Location">12, 9</Property>
      <Property name="DataBindings">
        <Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
      </Property>
    </Object>
    <Property name="Name">Form1</Property>
    <Property name="DataBindings">
      <Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
    </Property>
    <Property name="ClientSize">292, 122</Property>
  </Object>

The xml serialization is achieved by a class derieved from BasicDesignerLoader and is replaceable. In such way we ar able to do with the designed Form whatever we need.

That's the beginning of the story. Now I need to learn more about the designer hosting to check if it is what I need. It looks very interesting at a first glance (which I presented here) and may be used in many other places. I will try to use it in my application and we'll see if user will be able to change the UI, I will be able to handle it easily, and everyone will be happy.

Posted on Sunday, February 26, 2006 1:16 PM Visual Studio | Back to top


Comments on this post: Allowing end-user to change application UI

# re: Allowing end-user to change application UI
Requesting Gravatar...
Thanks to Jay, who gave me link to a site that shows how to host the designer in .NET 1.x:

http://www.divil.co.uk/net/articles/designers/hosting.asp
Left by Marcin Celej on Mar 29, 2006 3:29 PM

Your comment:
 (will show your gravatar)


Copyright © Marcin Celej | Powered by: GeeksWithBlogs.net