Tuesday, June 1, 2010

Creating a multi-shell application in Prism-v2

Creating a multi-shell application in Prism-v2: "

This thread from the Prism forum presents the following question (this is not an actual quote but a summary): Are there any examples with multiple Shell windows, as the Prism documentation mentions?

First I re-read this article from the Prism documentation so I could get in the same page as the user. I’m not going to quote it here, but the “Implementing a Shell” section is the one where it is explained. Once I read that, the popular Popup Region from the Prism-v2 RI was out of the table so with Ezequiel Jadib we decided to create a small spike to see what changes needed to be done.

Creating Multiple Shells

As in a regular Prism application, using the CreateShell method to create the new Shell seemed like a good approach. However, as the RegionManager is set to the DependencyObject returned by this method, this had to be done manually for any other Shell window.

protected override DependencyObject CreateShell()
Shell1 shell = new Shell1();
Shell2 shell2 = new Shell2();

RegionManager.SetRegionManager(shell2, this.Container.Resolve<IRegionManager>());

return shell;

When to close the application?

Another thing to determine is when to close the application. This is not something “Prism specific” as WPF provides this option for any application. Since there are multiple Shell Windows, choosing the ShutdownMode=”OnLastWindowClose” seemed like the best approach.

<Application x:Class=HelloWorld.App

Sample Application

I created a small sample application which publishes an event in one of the Shell views and subscribes to it in the other. You can download it from here. The code is provided “AS IS” with no warranties and confers no rights.


Shout it


No comments:

Post a Comment