How to get the Parents

Topics: Prism v2 - WPF 3.5
Apr 2, 2009 at 6:17 AM

if I use nested regions, how can I get the parent region of a view and the parent view of a region?
Apr 3, 2009 at 8:40 PM

Hi jaga,


This is not a usual scenario. In general views should not be aware in which region they are located nor regions know their parent views. There are of course tricks to get what you are looking for but you will be probably breaking modularity or coupling modules.


If what you are looking for is a way to share some contextual information between the region and its children, you should use the RegionContext. You can find more information on how to use the RegionContext in the Communication and  UI Composition Technical Concepts of the documentation.


To get the region in which a view is defined you can do something like the following:


                IRegion region = regionManager.Regions.First(r => r.Views.Contains(yourView));


You can obtain a reference to the regionManager using dependecy injection. You might find useful the How to: Show a View in a Scoped Region


If you what to get the WPF control that the region is mapped to, you can generally query the view's Parent property (That is equivalent to using the LogicalTreeHelper.GetParent method):

               ContentControl control = view.Parent;



Hope it helps!


Matias Bonaventura

Apr 4, 2009 at 5:02 PM
Thank you for the answer, Matias.

yes, we have a special scenario. Our program have many scenes (WorkItems). Each scene consist of several views and regions. If I call a scene, it integretes itself in the scoped regions/views of the parent (caller) scene using dependency injection.
If I close the scene it knows only his own views and regions, but to remove them I have to know theirs parents too. I thought there is may be an out of the box solution. If not, I have to save a reference of the parents during the integration, or I have to use dependency injection again. (and the user schould not have permits to move views to an other region)