Grab Shell Form Reference from Module.

Topics: CAB & Smart Client Software Factory
Dec 31, 2005 at 5:46 AM
originally posted by: KristianPaul

Let's say for example I want to create a ModuleLayoutInitializer object that is responsible for building the Shell's UI. What is the best way to get a reference to the Shell Form from a module?
Dec 31, 2005 at 8:10 AM
originally posted by: BradWilsonMSFT

We don't provide direct access to the shell from anywhere but the application. Our general usage scenario is that the shell will provide core services like menus, status strips, tool strips, etc., with named UI extension sites, and the main body of the window will be carved up appropriately with workspaces.

If you (still) want direct access to the shell from somewhere else, something you could do is register the shell as a service. In your application class, override AfterShellCreated like so:

protected override void AfterShellCreated()
{
base.AfterShellCreated();
RootWorkItem.Services.Add<MyShellForm>(this.Shell);
}

Then anybody who needs direct access to the shell can query their work item (or use ServiceDependency) for the concrete type of the shell.