Prism+Mef+Regions+Share Childwindow with modules

Topics: Prism v4 - Silverlight 4
Oct 21, 2010 at 7:21 PM
Edited Oct 22, 2010 at 5:28 PM

Hy again guys,

I'm trying to design the structure of my application and I'm having some doubts.

Let me try to explain how it will work my application:

I Have a Shell with a "MainRegion" and 2 modules:

  - ModuleA : that have a ViewA, and a ChildWindowA

  - ModuleB : that have a ViewB, and a ChildWindowB

In the Shell i have 2 buttons (show ViewA and show ViewB).

The ViewA and ViewB is just a DataGrid that load the TableA and TableB data respectively, and also have 3 buttons (add, edit and Delete).

The Add and Edit buttons for the ViewA call the ChildWindowA, and the Add and Edit buttons for the ViewB call the ChildWindowsB.

Thats all fine,no problem here.

The problem is: The ChildWindowA (in the ViewA), also have a shortcut to add a TableB record, so, i need to call the ChildWindowB (in the ModuleB) inside the ChildWindoA (in TheModuleA), how can i do that?

------- -----

Given the structure above, ill will use the Ria Service as a Data Context in my Application.

In that case, is there any problema to create a Singleton DomainContext in the Shell? that all my Modules/Views/Childwindows can use?

Oct 22, 2010 at 7:04 PM
Edited Oct 22, 2010 at 7:05 PM


Based on my understanding, you have a PopupRegion in your ViewA and other in the ViewB (also named SecondaryRegion in the StockTrader RI). And, you are registering/adding your popup views in these regions.

Additionally, you need to show the PopupViewB from the your ViewA. So, for achieving this scenario, you have two possible options within sight:

1) Expose your Shell Window as a region and display all your dialog windows in that region. For more information on this topic, you could take a look at the Stock Trader RI, since it has already implemented this scenario

2) If you have two different regions for displaying your dialogs:

  • Use View Injection and add your ViewB to the PopupRegionA using the following code (pseudo-code):


  • Use Navigation and navigate to your ViewB in the PopupRegionA using the following code (pseudo-code)

regionManager.RequestNavigate("PopupRegionA", new Uri("/PopupRegionB", UriKind.Relative));

Hope this helps.

Fernando Antivero


Oct 22, 2010 at 7:43 PM

The Popup is not a region, thats the problem.

The popups, in my Application are Childwindow (a modal windows from silverlight Toolkit), that arent in a region. so how can i do that?

My Shell have only one region ("MainRegion"), that i load a ViewA, with datagrid and some buttons. The button call a ChildWindows (modal windows) to the user enter the data, but in that windows i need to call another ChildWindow that is in another module.

And i need to pass parameters to that Windows.

Is there a way to do that with Prism? 

Oct 22, 2010 at 8:57 PM


There is not guidance on using the ChildWindow (Silverlight Toolkit) in Prism out-of-the-box. But the recommended approach for displaying dialogs is implemented in the Stock Trader RI.

Therefore, I would recommend you to check the Stock Trader Reference Implementation Application, since this application implement a pretty similar scenario as you described.

The Shell Window contains a "MainRegion" and also it exposes a "SecondaryRegion" to display all the dialog windows in the application:

<UserControl x:Class="StockTraderRI.Shell"
    infBehaviors:RegionPopupBehaviors.ContainerWindowStyle="{StaticResource PopupStyle}">
            <!-- main bar -->
            <ItemsControl x:Name="MainToolbar" Regions:RegionManager.RegionName="MainToolBarRegion" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,10,0" Grid.Row="1" RenderTransformOrigin="0.5,0.5">
            <!-- content -->
            <Controls:AnimatedTabControl Regions:RegionManager.RegionName="MainRegion" Opacity="1" ... />            
            <ContentControl Regions:RegionManager.RegionName="ActionRegion" x:Name="ActionControl" LayoutUpdated="ActionControl_LayoutUpdated" >

Then, you could take a look at the PopupDialogActivationBehavior.Silverlight.cs class, since it helps to display the dialog windows in the SecondaryRegion by providing the wrapper class (IWindow), which manages the control to be displayed.

So, you will be able to modify/create this behavior to use the control of your choice (e.g. ChildWindow) and if you have any particular problem implementing this, you could ask for help here.

Hope this helps.

Fernando Antivero


Oct 22, 2010 at 9:41 PM

i ll take a look at the  PopupDialogActivationBehavior.Silverlight.cs, but let me show you my temp solution:

My App:

  • App (Main Project)
  • ModuleA
    • ViewA
    • ChildWindowA
  • ModuleB
    • ViewB
    • ChildWindowB (that needs to call the ChildWindowA)
  • Lib (Silverlight Library Project)

So, in the Lib project a declared an Interface:


public interface IChildWindowA
   void Show(/* pass ViewModal and Current Record to update*/);


in the ChildWindowA, implements the Interface


public partial class EditTemp : ChildWindow, IChildWindowA
   public void Show(...)


The ModuleB DependsOn the ModuleA, In a Button Click inside the ChildWindowB in the ModuleB:


private void OnButtonClick(object sender, RoutedEventArgs e)
   _editWindowA = (IChildWindowA)ServiceLocator.Current.GetInstance(typeof(IChildWindowA));

Is that a Bad Solution? or i can go with that




Oct 25, 2010 at 2:21 PM


Although it is a possible approach for achieving your scenario, please take into account that in general you will find the recommended approaches by the product team in the Quickstarts and Reference Implementations provided in Prism.

That said, note that you are loosing the ability of UI Composition since you do not use regions, while the recommended approach provides you an homogenized way for displaying views in your application.

But it is important to remark that if you consider that the recommended approach does not fit with your scenario, you could use either the implementation that you shared or others.

Hope this helps.

Fernando Antivero