WPF Prism 将用户控件设置为 Shell



我是WPF Prism的新手,我看过很多关于Prism的在线文章,我发现所有的示例代码都使用Windows应用程序作为shell,所以我有一个问题,我可以让用户控制作为shell吗? 如果不是为什么?

shell 应该是一个窗口,因为 WPF 应用程序始终具有顶级窗口(除非作为 XBAP 托管在浏览器中(,但您可以在引导程序的InitializeShell()方法中将窗口的Content设置为用户控件:

protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Content = new UserControl();
Application.Current.MainWindow.Show();
}

UserControl必须托管在窗口或页面中。它不是顶级控件。

  1. 窗口可以单独打开;而用户控件不能。这就是为什么顶级窗口必须是窗口的原因。
  2. 用户控件还可以包含区域。这允许您使用区域将用户控件嵌套在另一个用户控件中。

最新更新