Prism : Add a window in a region

Topics: Prism v2 - WPF 3.5
May 7, 2010 at 11:59 AM
Hi, I'm new working with Prism with WPF, and I have a question which I can't find answer. Why it is impossible to add a window in a Region ? I can understand there's a good reason, so I will need another solution to my problem. It is quite simple, I got a LoginView (Window) which I want to appear first. For the previous reason, in my Region, I added a MainView (UserControl) where I just show my LoginView on the Loaded event. The problem if the user quit the application or if he cancels his login, the MainView is still showing up. It seems a stupid problem, but I can't find a smart solution. Thanks for your time.
May 7, 2010 at 6:03 PM


You can’t add a window inside a Region because in WPF a Window class must be the root of the logical tree, and since regions are controls that are children of another Window, you would be doing an invalid operation in terms of the WPF hierarchy. You can find a more detalied explanation on this article.

You could use the RegionPopupBehavior to show views in another window. You can check these threads for more information about this:

Show modal dialogs with subregions in Prism app

As for the login functionality, a possible approach would be to make the Bootstrapper create a separate window where the login is performed before loading the Shell. Then you should add a call to an authentication service in your CreateShell method in the Bootstrapper so that the shell is created only if the user is authenticated. In case the user isn’t authenticated, you could simply close the application, as shown on this thread.

An example would be something like this:

protected override DependencyObject CreateShell()
    if (Container.Resolve<IAuthenticationService>().IsAuthenticated(User))
        Shell shell = new Shell();
        return shell;

You can also check these threads for alternative ways to achieve login functionality, by showing a login modal dialog before creating the shell:

Show login modal form before
Best practice to launch login modal before the shell

I hope you find this helpful.

Guido Leandro Maliandi

May 10, 2010 at 3:30 PM
Unfortunately, we changed our approach for the project, so this problem is no more an obstacle for me. This said, that's a great answer and this could help a lot of people, even me when it will be necessary again. Thank you very much for your time.