在 WinForm ElementHost 中托管 Prism 的问题 [英] Problems with Prism hosted in a WinForm ElementHost

查看:47
本文介绍了在 WinForm ElementHost 中托管 Prism 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ElementHost 控件中托管 WPF 棱镜应用程序时遇到问题,急需帮助.

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

PRISM 应用程序在 Silverlight 和独立 WPF 中运行良好.

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

主 Shell 似乎在 WinForm 上的 elementHost 中设置得很好,但是其他视图仅加载RegisterViewWithRegion"而不是添加,激活"过程.我需要添加,激活"来确定范围.但是我相信问题是我加载了我的 shell 两次......不是故意的.我找不到调用引导程序并设置 elementHot 而不调用Resolve"两次的方法.

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.

这是我的 WinForm 和引导程序的代码.再次使用RegisterViewWithRegion"时一切正常.

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

这是 Winform 构造函数:

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;
    }

这是引导程序:

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

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

    }
}

推荐答案

我有同样的 GCE(严重概念错误).在使用 Add 或 Activate 时,我看到我的视图被实例化了两次的相同行为.当它袭击我时,我正在深入调试这些行为.

I had the same GCE (Gross Conceptual Error). I was seeing the same behavior of my views being instantiated twice when using Add or Activate. I was deep into debugging the behaviors when it hit me.

以下是返回 ShellContainer 的新实例.

The following is returning a new instance of the ShellContainer.

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

要么使用 ContainerControlledLifetimeManager 在容器中注册您的 ShellContainer 类型,要么在您的引导程序上放置一个 prublic 属性以访问 ShellContainer 实例以设置到您的 ElementHost 中.

Either register your ShellContainer type in the container with a ContainerControlledLifetimeManager or put a prublic property on your bootstrapper to access the ShellContainer instance to set into your ElementHost.

这篇关于在 WinForm ElementHost 中托管 Prism 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆