Designer Hosting

There have been a lot of improvements for designer hosting in Whidbey. The task of creating a host form that hosts other designers in Everett is a huge task requiring probably 100s of lines of code. In Whidbey it is down to <10 lines. More on this further down.
But first - What exactly is designer hosting? Simply put it is hosting designers. To understand how hosting works it is important to understand what a designer is in .Net Framework. Simply stated, a designer in the .NET Framework is an object that only exists at design time, and connects to an object that normally exists at runtime. Consider a Button on a Form. At runtime these two objects are associated with each other only by a parent-child relationshipt. At design time the picture is a little more complex. At design time each of them has a designer. So we now have Form, Form designer, Button and Button designer. They are also connected to a host container. The host container has a lot of responsibilities. It provides various services needed by these objects eg. Selection Service to select these objects, Component change Service, etc. It is also responsible for loading designers from some sort of persistent state, and saving them back to that state.

On a high level, we have 3 parts to host designers: Host container, Designer Loader and Serializers.

Host container is the object that implements IDesignerHost - the most important interface for designer hosting. IDesignerHost provides some organization to the random array of designers that components provide. It also holds a reference to DesignerLoader. DesignerLoader is the piece that is responsible for loading the designers and saving the state back. To do this it uses Serializers.

In Whidbey we have a class called DesignSurface that encapsulates all this. To demonstrate how simple it should be for a third party to host a designer, the following sample code will create a Windows Forms designer and display it:

DesignSurface ds = new DesignSurface();

ds.BeginLoad(typeof(Form)); // loads the Form

IDesignerHost idh = ds.GetService(typeof(IDesignerHost)) as IDesignerHost;

Control view = ds.View as Control; // Gets the View of the DesignSurface

Form f = new Form();


view.Dock = DockStyle.Fill;

f.Show(); // Show the View on a Form