Prism V2: Hosting Shell in WPF/WinForm Application

Topics: Prism v2 - WPF 3.5
Oct 29, 2009 at 6:25 PM

Hi All,

I am trying to make Shell as UserControl in WPF Composite application. I Started by modifying the Quickstart app: "Quickstarts\UI Composition\ViewDiscovery". I made "UIComposition.Desktop.csproj" a UserControl class library with Shell.xaml as UserControl. Created another WPFApplication to host the Shell. Added the following code in App.xaml.cs:

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Bootstrapper bootStrapper = new Bootstrapper();
bootStrapper.Run();
// Get ShellContainer from IOC
IUnityContainer container = bootStrapper.Container;
var shellElement = container.Resolve<Shell>();
ShellContainer win = new ShellContainer();
// Add the ShellContainer UserControl to the main window
win.mygrid.Children.Add(shellElement);
win.Show();
}

The form shows up with the shell but when I click on the employee it doesn't show the details view. Please help!!! If any body has tried this.
Thanks & Regards,
Vishal.

Oct 30, 2009 at 8:38 PM

Hi,

When you need to create a specific kind of Shell window, for example as you mentioned, based on an UserControl, you should override the CreateShell method of the UnityBootstrapper class in order to put the Shell creation logic.

A proposed solution to perform this, it is to create a Bootstraper class, which inherits from the UnityBootstrapper class and override the CreateShell method.

The following code implements the aforementioned solution:

Bootstrapper implementation

internal class Bootstrapper : UnityBootstrapper
{
    protected override DependencyObject CreateShell()
    {
        // Get ShellContainer from IOC
        var shellUserControl = this.Container.Resolve<ShellUserControl>();
        ShellContainer shellContainer = new ShellContainer();
        // Add the ShellContainer UserControl to the main window
        shellContainer.mygrid.Children.Add(shellUserControl);
        shellContainer.Show();
        return shellContainer;
    }
    //more code here...
}

App.xaml.cs

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        Bootstrapper bootStrapper = new Bootstrapper();
        bootStrapper.Run();
    }
}

I hope you can find this answer helpful.

Fernando Antivero
http://blogs.southworks.net/fantivero

Nov 1, 2009 at 6:24 PM

Hi fantivero,

Thanks for replying. As I said Shell is a Usercontrol class library which is hosted in another WPF/WinForm Application. When i tried this approach with the quickstart app: "Quickstarts\UI Composition\ViewDiscovery", Employee details view is not visible in the shell.

To reproduce the problem, modify the quickstart proj "UIComposition.Desktop.csproj" as a user control proj with shell as usercontrol and host it another WPF/winform application.

Thanks & Regards,

Vishal.