我在ElementHost控件中托管WPF prism应用程序时遇到了问题,我需要帮助。
PRISM应用程序在silverlight和独立的WPF中运行良好。
主外壳似乎在WinForm上的elementHost中设置得很好,但是其他视图只使用“RegisterViewWithRegion”加载,而不是“添加,激活”过程。我需要“添加,激活”来确定作用域。然而,我认为问题在于我加载了两次…不是故意的。我找不到一种方法来调用bootsrapper并设置elementHot,而不调用“Resolve”两次。
下面是我的WinForm和引导程序的代码。同样,使用"RegisterViewWithRegion“时一切正常。
下面是Winform构造函数:
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();
}
}发布于 2009-12-21 22:33:21
引导程序自动将Application.Current.MainForm设置为您在CreateShell方法中返回的任何内容。希望您正在设置一个应用程序(我认为这就是您在第一个If代码块中要做的事情)。如果是这样的话,您只需更改以下内容:
var shellElement = bootStrapper.Container.Resolve<ShellContainer>();要这样做:
var shellElement = Application.Current.MainForm;这应该是可行的,但ElementHost确实有一些奇怪的地方。我们最终得到了许多奇怪的渲染错误,特别是在Citrix环境中。我不知道这是否是您的设置的限制,但我想我应该提一下。
祝好运!
发布于 2010-07-13 20:48:08
我也有同样的GCE (粗大概念错误)。在使用Add或Activate时,我看到我的视图被实例化了两次。当我意识到这一点时,我正在深入调试这些行为。
下面返回一个新的ShellContainer实例。
var shellElement = bootStrapper.Container.Resolve<ShellContainer>();在容器中使用ContainerControlledLifetimeManager注册您的ShellContainer类型,或者在引导程序上放置一个公共属性,以访问要设置到ElementHost中的ShellContainer实例。
https://stackoverflow.com/questions/1935701
复制相似问题