【发布时间】:2014-02-22 12:46:21
【问题描述】:
在 WPF/PRISM 中,当您创建 shell 时,它将分配给App.Current.MainWindow。但是在浏览器中的 WPF (XBAP) 中,该行:
App.Current.MainWindow = (Window)Shell;
失败并显示错误消息:
无法将“XBAPClient.Page1”类型的对象转换为“System.Windows.Window”类型。
protected override DependencyObject CreateShell()
{
return this.Container.GetExportedValue<Page1>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)Shell;
App.Current.MainWindow.Show();
}
如何加载外壳?
【问题讨论】:
-
如果您使用 XBAP,您将使用 Page 而不是 Window。所以你不能将 Shell 转换为 Window。有关更多信息,请查看此线程:compositewpf.codeplex.com/discussions/…
-
更新:我已关注第一条评论。说明很好。然而仍然没有运气。调查它为什么不运行。但至少它的建筑。谢谢
-
@kmatyaszek 不幸的是,
CreateShell先被调用,然后Page1.xaml.cs才能设置Bootstrapper.ShellPage = this;因此它返回一个始终为空的 shell。你有什么建议吗? -
我已经找到解决方案,请检查我的答案。