1
votes

I'm new to WPF Prism, I have seen many online article about Prism and I found all of example code are using windows application as shell, so I have a question, can i let UserControl as a shell? if not why?

2

2 Answers

1
votes

The shell is supposed to be a window since a WPF application always has a top-level window (unless hosted in a broswer as an XBAP) but you could set the Content of the window to a user control in the InitializeShell() method of your bootstrapper:

protected override DependencyObject CreateShell()
{
    return Container.Resolve<MainWindow>();
}

protected override void InitializeShell()
{
    Application.Current.MainWindow.Content = new UserControl();
    Application.Current.MainWindow.Show();
}

A UserControl must be hosted in a window or page. It is not a top-level control.

0
votes
  1. The Window can be opened alone; while the UserControl can’t. That is why the top-level window must be a Window.
  2. The UserControl can also contains Regions. This allows you to nest a UserControl in another UserControl using Regions.