Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

Commented Unassigned: RegionManager null (not inherited) on views when ViewModel First is leveraged [10276]

$
0
0
When using a ViewModel first approach (whereby a viewmodel is registered with a region, and a view is assigned via data templates defined within a resource dictionary), the RegionManager for the View is not inherited via the visual tree. Instead it is null, and all nested regions aren't registered with the IRegionManager declared within the container.

Expected Result:
The View's RegionManager should correspond to the inherited regionmanager of the visual tree if not explicitly set.

Actual Result:
The View's RegionManager is null.

Possible Solution:
Change the RegionManager.RegionManagerProperty to allow inheritance. Example:
```
public static readonly DependencyProperty RegionManagerProperty =
DependencyProperty.RegisterAttached("RegionManager", typeof(IRegionManager), typeof(RegionManager), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));
```


-Richard
Comments: ** Comment from web user: DCherubini **

Hi Richard,

This is a known problem since early versions of Prism.
Basically, when a new __Region__ is created its __RegionManagerRegistrationBehavior__ is the one in charge of registering the __Region__ in the corresponding __RegionManager__. In order to do so, the behavior "climbs up" the logical tree recursively using the __Parent__ property until an element that has a __RegionManagerProperty__ attached is found.

The problem is that some elements such as __DataTemplates__ do not expose a __Parent__ property and hence, the aforementioned behavior is unable to "climb up" pass them. The result is that the __Region__ contained inside the __DataTemplate__ is not added to the __RegionManager__ as expected.

In the meantime, there are several approaches and workarounds that can be used to avoid this problem. One of them, for example, is portrayed in the following blog post:
* [Regions inside DataTemplates in Prism v4 using a region behavior](http://blogs.southworks.net/dcherubini/2011/11/10/regions-inside-datatemplates-in-prism-v4-using-a-region-behavior/)

Thanks,

Damian Cherubini
http://blogs.southworks.net/dcherubini


Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>