Prism Region Manager and Data Templates

When you add a view to a region (Region.Add(view)), it could be a real view, or a data template from which the view is created. The region tries to associate current region manager with the view by setting the IRegionManager.RegionManager property on it. This is useful if the view has its own regions, and this is crucial if the view is a root of new region scope.

To do so, they cast the view to DepenencyObject and if the cast is successful, set the property. When some regions are found in the view or its children, Prism will walk up the logical tree to find the region manager. This will work fine if the view is the real view, but it will break miserably if the “view” is a data object and the real view is created from data template / content presenter.

Leave a Reply

Your email address will not be published. Required fields are marked *