Problems with Prism hosted in a WinForm ElementHost

Posted by rabozo on Stack Overflow See other posts from Stack Overflow or by rabozo
Published on 2009-12-20T12:30:26Z Indexed on 2010/04/09 18:33 UTC
Read the original article Hit count: 890

Filed under:
|
|
|
|

I am having problems with hosting a WPF prism app in an ElementHost control and am desparate for help.

The PRISM app runs fine in silverlight and in a standalone WPF.

The main Shell seems to setup fine in the elementHost on a WinForm however other views only load with the “RegisterViewWithRegion” and not the “Add,Activate” procedure. I need “Add,Activate” for scoping. However I beleive the problem is that I am loading my shell twice … not on purpose. I cannot find a way to call the bootsrapper and set the elementHot without calling “Resolve” twice.

Here is the code for my WinForm and my bootstrapper. Again everything works when using "RegisterViewWithRegion".

Here is the Winform Constructor:

   public Form1()
    {
        InitializeComponent();

        if (System.Windows.Application.Current == null)  
        {
            new MyApp();
        }

        Bootstrapper bootStrapper = new Bootstrapper();
        bootStrapper.Run();

        var shellElement = bootStrapper.Container.Resolve<ShellContainer>();

        //Attach the WPF control to the host  
        elementHost.Child = shellElement;
    }

Here is the bootstrapper:

public class Bootstrapper : UnityBootstrapper
{
    protected override DependencyObject CreateShell()
    {
        return Container.Resolve<ShellContainer>();
    }

    protected override void InitializeModules()
    {
        IModule moduleSurvey = Container.Resolve<SurveyModule>();
        moduleSurvey.Initialize();

    }
}

© Stack Overflow or respective owner

Related posts about prism

Related posts about winforms