How to know when Regions are finished loading for a view

Topics: Prism v4 - WPF 4
Mar 21, 2011 at 9:46 PM
Edited Mar 21, 2011 at 9:47 PM

Case is simple, I have a view with two new regions. The view is loaded with view injection.

I tried using the IActiveAware and adding the views to the regions from the event, but at this point the new regions aren't discovered/registered yet, and I get an exception.

So, how can I get notified when the new regions in my view are loaded and ready to be populated with views?




Mar 22, 2011 at 3:20 PM

Hi Ronny,

One possible way to achieve your requirement could be to subscribe to the CollectionChanged event in the RegionManager´s Regions collection (since it’s an ObservableCollection). By doing so, when a region is loaded and then added to the collection, you will be notified in the event handler you’ve specified.

This is possible because of two region behaviors: the DelayedRegionCreationBehavior and the RegionManagerRegistrationBehavior. The former is responsible for creating the regions only when the control that will host it is added to the region tree, and the latter is responsible for registrating the newly created region to the RegionManager; hence, you are guaranteed that the CollectionChanged event will only be raised when a region is actually loaded, and its control displayed. Take into account that, in order to know when a region has been added, in the event handler for the CollectionChanged you should check whether the NotifyCollectionChangedAction is“Add”.

I hope you find this information useful.


Miguel Bronzovic


Apr 11, 2011 at 6:54 AM

It was very useful! :)