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();
          shell.Show();
          shell2.Show();
          shell.Activate();

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

          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.Appxmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:x=http://schemas.microsoft.com/winfx/2006/xamlShutdownMode=OnLastWindowClose>

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.

image

Shout it

6 Responses to “Creating a multi-shell application in Prism-v2”

  1. DotNetShoutout Says:

    Creating a multi-shell application in Prism-v2…

    Thank you for submitting this cool story - Trackback from DotNetShoutout…

  2. Twitter Trackbacks for Damian Schenkelman’s Blog » Blog Archive » Creating a multi-shell application in Prism-v2 [southworks.net] on Topsy.com Says:

    [...] Damian Schenkelman’s Blog » Blog Archive » Creating a multi-shell application in Prism-v2 blogs.southworks.net/dschenkelman/2010/01/26/creating-a-multi-shell-application-in-prism-v2 – view page – cached 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? [...]

  3. Ahmed Says:

    Thanks for your sharing.

    Can you please provide us of a way to open multiple window in a single shell?! not multiple shells.

    Thanks

  4. Damian Schenkelman Says:

    Hi Ahmed,
    I am not sure what precise scenario you want to achieve, but a common way to have multiple windows and a single Shell is using the RegionPopupBehaviors from the Prism RI (or update it to suit your needs).

    This thread might be useful for you as well.

    Thanks,
    Damian

  5. Ahmed Says:

    Thanks :)

    The scenario is that we have a ribbon control on the shell and we are using the RibbonRegionAdapter. Our client needs to open multiple windows in the same shell and make the ribbon operate on this new window. So, if the new window is active and I click on a ribbon button then it acts on this new window and if I return to the shell it act on the shell.

    So any suggestion beside your last reply?!

    and Thanks in Advance

  6. frosty Says:

    Hello,

    Looking at this sample, an example of having multiple shells would be having a ribbon bar or some sort of menu which would need to load different shells with different layouts.

    For example, take Northwing and you have a Customer Module that needs a specific set of regions. Then you have an employee module that needs an entirely different shell regions laid out.

Leave a Reply