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

New Post: RegionManager does not contain nested region issue

$
0
0
I'm afraid you can't access the nested regions in OnNavigateTo, it is too early in the view lifecycle of the region. Regions are defined with an attached property and the implementation uses a DelayedRegionCreationBehavior that has to wait until the Visual Tree is created to determine what kind of element it is being attached to so that it can select the appropriate region adapter. And basically the visual tree does not come into being until after construction of your view class and before the Load event fires. So the Load event is the only reliable place to know that any contained regions have been created and the RegionManager is aware of them.

The way I typically deal with these kinds of things that are dependent on waiting for view load is to use a CallMethodAction behavior in the view to call a "Loaded" or "Initialized" method in the ViewModel based on the Loaded event in the view (tied in with an EventTrigger on the behavior). If what you need to do depends on the arguments passed to the OnNavigatedTo method, then store those parameters in a ViewModel variable when it gets called, and do the handling in the method called when Loaded fires.

Viewing all articles
Browse latest Browse all 1878

Trending Articles