Subregions, ViewModels / AddToRegion / RegisterViewWithRegion

Topics: Prism v2 - WPF 3.5
Jun 16, 2009 at 6:54 AM

Hi,

I'm noticing some perculiar things happening with Regions. Anyone seen this:

Module A

ViewA (with subregion MySubRegion)

ViewAViewModel.

If in Module A I call RegisterViewWithRegion passing a func to return ViewA, then I get MySubRegion registered as a region.

If in Module A I call AddToRegion passing a concrete ViewA, then I _do not_ get MySubRegion registered as a region.

If I use WPF typed data templates to associate ViewAViewModel with ViewA via a resource dictionary then it doesn't matter whether I call RegisterViewWithRegion or AddToRegion. Either way I _do not_ get MySubRegion registered as a region.

Can anyone shed any light on this?

Thanks,

Graeme

 

Jun 16, 2009 at 9:50 AM

So with a bit more research I've realised that:

There is a method called RegionManagerRegistrationBehavior.FindRegionManager which runs up through the logical tree looking for the Region Manager. When a typed data template (viewmodel poco) is dropped directly into the tree though the LogicalTreeHelper.GetParent returns null when it hits it.

I've made a change to my own version which says this:

            parent = LogicalTreeHelper.GetParent(dependencyObject);
            if (parent == null)
            {
                parent = VisualTreeHelper.GetParent(dependencyObject);
            }

However I'm hitting all the same issues around RegionContext and other DP's which Prism attempts to set on my ViewModel but realises it can't. Frustrating that the Pattern de jour can't be used easily.

Question to the authors - why aren't inherited DP's used? It would clean up the _WPF_ soooo much. The codebase looks really comprimised and more complex because of the cross-compilation for WPF and Silverlight.

Cheers,

Graeme