RegisterViewWithRegion problem with Scoped Region

Topics: Prism v2 - WPF 3.5
Jun 18, 2009 at 5:24 AM


I've knocked a sample application up which has a shell with a tabcontrol region. The tabcontrol contains a search view which contains a TabControl ResultsRegion. The search view is added with createRegionManagerScope set to true. The problem I have is that I've called RegisterViewWithRegion from a couple of other modules. When the Search view is added the views I registered against ResultsRegion get added and given a null RegionManager _before_ Prism sets the RegionManager on the containing control (the search view).

I'm trying to use RegionManager to control communication scope, i.e. within a region, and don't see how you can use RegisterViewWithRegion given this issue.

Any advice would be really appreciated.



Jun 19, 2009 at 8:05 PM

Hi Graeme


If I understand your scenario correctly, you are registering in your scoped region views from different modules. However, at the moment of registering the views, you are not able to get the region manager because it is being set after the registration is done.


This is the typical scenario where ViewDiscovery should be used, since you do not know whether a region with that name will be registered but you know your view has to be shown in it. The benefit is that the region does not have to exist at the time of registration, so you do not have to worry about whether the region has already been created or not (no timing initialization issues). As you said, what is probably happening is that your views are being registered before the search view is added to the TabControl region.


A possible option could be using the RegionContext as a communication mechanism between your regions. You can check out the ViewDiscovery Quickstart solution shipped with Prism for an example of this.


You can read more about the region context in these articles:

·         Communication

·         UI Composition

Please let me know if this helps.


Damian Schenkelman

Jun 20, 2009 at 12:39 AM

Hi Daniel,

Thanks for the quick response - the issue is slightly different to what you are explaining.

My Views are all registered using Region Discovery. The region they request to be showed in is contained on another View that is showed as a Scoped Region. The problem is that the Region Discovery is taking place _before_ the View which is Scoped is given its own Region Manager. i.e. Prism seems to load the View, spot the new Region, run the Region Discovery, give the discovered views a 'null' region manager before it gives the view that registered the Region it's own Region Manager. It looks like an issue which wouldn't exist had the DP's were inherited through the tree.



Jun 20, 2009 at 12:43 AM

I should add what I'm trying to achieve - I want to know what the best practice of giving context to a set of views that are related to some greater purpose - 

I tried using RegionContext but didn't see how I could test it very easily as the RegionContext needs a Dependency Object - using mock views that cast would fail.

So I decided to raise events when the context changed but needed a way to identify a group of views related to the same customer. So I thought if they shared a common Region Manager that I could pass that in the event and all subscribers could check if they were using the same Region Manager.

What is the best way to deal with this issue?