Close view that defines a Region

Topics: Prism v4 - Silverlight 4
Feb 17, 2012 at 12:50 PM

I have a view let's call it 'NestedView', which defines nested region, due to lack of nested region support in XAML I create a view in UserControl constructor like this:


RegionManager.SetRegionName(RegionControl, "MyRegionName");
RegionManager.SetRegionManager(RegionControl, _globalRegionManager);

'NestedView' is shown (added) to some region let's call it 'MainRegion', at some time I need to close this view (remove it from 'MainRegion'). But If I simply remove 'NestedView' from 'MainRegion', the region it has registered 'MyRegionName' will remain registered, and the next time I will try to open 'NestedView' it will throw exception that region 'MeregionName' already registered.


So I need to make sure that when I close view that contains regions, they are unregistered, and all views they contain are disposed. What is the best way to do this?


Feb 17, 2012 at 2:50 PM


I believe, your problem might be related to a known memory leak issue in prism when removing view with child regions inside, you could find more information about this and a possible work around in the following work items:

Additionally, you might find useful to know that since Prism 4.1 final release, to support this scenario, an optional behavior was added that will clear the RegionManager attached properties on those regions to force their removal from the region manager.

You could find more information about this changes this in the Prism 4.1 readme.mht file included in this release.

I hope you find this helpful,

Agustin Adami