• Creating a multi-shell application in Prism-v2

    Published by Damian Schenkelman on January 26th, 2010 11:55 am under Composite Application Guidance for WPF & SL, Patterns & Practices, Prism-v2, Prism-v2.1, WPF, Windows Presentation Foundation, p&p

    7 Comments

    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.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ShutdownMode="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

    Tags: , , , , , ,

  • 7 Comments:

    1. DotNetShoutout said on January 26, 2010:

      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 said on January 26, 2010:

      [...] 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 said on February 8, 2010:

      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 said on February 13, 2010:

      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 said on February 13, 2010:

      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 said on February 17, 2010:

      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.

    7. Sara said on January 4, 2013:

      Related to this. I would like to know how to create a Prism app that defers creation of the shell until after some validation takes place in some of the modules.
      If this is not possible or too complex: how can I call a Prism application passing parameters from a Console application?

    Leave a comment

    Your email address will not be published.

Categories

Archives

Map

SO Profile

Certifications

Microsoft Certified Professional Microsoft Technology Specialist (Silverlight 4 Development)