Define Region(s) in Childwindows using Prism + MVVM

Topics: Prism v4 - Silverlight 4
Nov 29, 2011 at 3:30 PM

I am using Prism + MVVM to Inject views in regions. I use several Childwindows using Interaction requests, but I am unable to define Regions in these Childwindows. The RegionManager isn't avaibale/accesible in the xaml and xaml.cs files. With Interaction requests, I can't add parameters in the constructor, to pass the RegionManager.

From the View that shows the Childwindow, we call the following Interaction request from the ViewModel:

private void PopupCmdExecute( string str )
                new ChildWindows.PopupViewModel(_eventAggregator),
                dialog =>
                    if (dialog.Result.HasValue && dialog.Result.Value)

The interaction trigger in the XAML (of the View that raises the popup window):

        <prism:InteractionRequestTrigger SourceObject="{Binding PopupRequest}">


The following XAML code is from the PopupView that holds the Region:

<controls:ChildWindow x:Class="ApplicationModule.Views.ChildWindows.PopupView"
           Width="780" Height="550" 

       <ContentControl prism:RegionManager.RegionName="PopupTestRegion" 
                       VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" />


Is it possible that I can still acces the RegionManager in the PopupView, without adding it to the constructor of the PopupView? (Because the interaction trigger 

doesn't allow parameters in the constructor...)
Nov 29, 2011 at 8:08 PM
Edited Nov 29, 2011 at 8:13 PM


As a possible approach you could obtain the proper RegionManager in the constructor of your PopupView and set it as a dependency property of the view:

public PopupView()
    IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
    this.SetValue(RegionManager.RegionManagerProperty, regionManager);

In the previous code snippet, a new RegionManager is obtained through the Service Locator, however you might need to use an existing RegionManager or to create a new one and access it outside your PopupView. For doing this you could, for example, use a shared service (e.g. an object registered as a singleton in the container) to pass the RegionManager to/from the PopupView and obtain the shared service through the Service Locator. However, the specific details of how to implement this depends mostly of your personal preferences and the requirements of your scenario.

As a side note, if you use the view discovery approach (for example, registering a view in a region with the RegisterViewWithRegion method) it's not required for the view containing the region (in this case the PopupView) to have a RegionManager attached.

Also, in case you require a PopupChildWindowAction with a custom behavior (like for example, accepting parameters for the view) you might find the following thread useful where you can find an example of a custom PopupChildWindowAction:

I hope you find this useful,

Damian Cherubini