how to get nested regionmanager or a region specified within a user control

Topics: Prism v4 - WPF 4
Jan 3, 2013 at 2:38 PM

Hi, 

I have a scenario in which I need to verify if a control is loaded in one of the region specified in another control. 

for eg:

Tab Control has a main region and I need access to one of the region in tab items to verify if a view is loaded. 

how do I achieve this? please help

Developer
Jan 3, 2013 at 8:00 PM

Hi,

As far as I know in Prism there is not direct functionality as out of the box to achieve this kind of scenario. As how to achieve it will depend on how your application is structured and how loosely coupled your components are.

In my opinion the main challenge will be to obtain the corresponding RegionManager where the specified region is registered. For example if your are using scoped regions this may not be straightforward. As a possibility, I believe you could retrieve the view from the main region where the specified region is defined. This could be achieved for example using the Region.GetView method in the main region assuming the view was registered using an specific viewName. And then the RegionManager.GetRegionManager method would become handy to obtain the corresponding region manager that was attached to this view. Although, this wont be required if you stored a reference to this RegionManager for example in a shared service or the corresponding view model.

Once you obtain the corresponding RegionManager, then you could iterate through the views collection of the specified region to check if the control exists in this region or not.

I hope this helps,

Agustin Adami
http://blogs.southworks.net/aadami

Jan 31, 2013 at 3:16 PM
Hi Agustin,

thank you for the response. and sorry for the delay.
I didn't get any notification for this thread at all. but yes. i had figured out your first approach suggested.
however you have mentioned about shared services storing reference to region manager. can you throw some light on this?

yes. i'm using scopedregion managers for the views. and still the code is bit buggy.

hope to hear from you soon
Developer
Feb 1, 2013 at 12:38 PM
Edited Feb 1, 2013 at 12:39 PM
Hi,

Regarding the approach using a shared service , what I meant was to have a way to centralize where these scoped region managers could be stored and accessed from. For example, this service could expose a key value pair Dictionary with the specific viewName as the key which could be used to identity the specific view and the corresponding scoped region manager as the value.

However, take into account that when following this approach you may have to add the additional logic to add and remove these key value pairs in sync with your existing views and a way to identity each of this views, which may result in additional complexity.

Regards,

Agustin Adami
http://blogs.southworks.net/aadami
Feb 1, 2013 at 2:20 PM
Thanks Agustin

Quite a nice approach to start with. I have a way to differential each views (using business object).
will try this approach. intriguing.

Kavya