ClearChildViewsRegionBehavior strange behavior

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
Mar 27, 2012 at 6:57 AM


I'm using prism 4.1 with ClearChildViewsRegionBehavior for removing all child views from nested region. Every time i'm creating new instances of views/viewmodels. And i see that private static void method ClearChildViews in ClearChildViewsRegionBehavior.cs executes only when i'm creating new instances of view/viewmodel, but not after removing view with nested regions from main region. Is this normal behavior?

Mar 27, 2012 at 6:17 PM
Edited Mar 27, 2012 at 6:22 PM


We could reproduce the scenario you mentioned. When we removed a view with nested regions inside using the ClearChildViews attached property. We realized that the Region_PropertyChanged method of the ClearChildViewsRegionBehavior was not being call until another change was made (for example by adding another view as you mentioned.) The reason for this behavior seems to be that the Region.Remove method doesn't call the RegionManager.UpdateRegions which notifies the attached behaviors to update the region managers appropriately, if needed. For example, this method is invoked when indexing the regions collection or adding a new view.

So far we didn't find any other undesired behavior than the aforementioned one. We believe a quick workaround could be to call the RegionManager.UpdateRegions() static method after removing the views, to achieve the proper notification to the attached behaviors.

Please let us know if this is your case and if you have encountered any other problem related to it.

I hope you find this useful,

Agustin Adami

Mar 28, 2012 at 5:48 AM
Edited Mar 28, 2012 at 5:55 AM

He aadami. Thank you. RegionManager.UpdateRegions() did the trick.

Mar 28, 2012 at 5:03 PM
Edited Mar 28, 2012 at 5:04 PM


I'm glad you found this workaround helpful. Additionally we have created this work item notifying about the behavior, so it can be taken into account for future releases.

Thanks for the feedback!

Agustin Adami