KeepAlive cause RegionContext lost

Topics: Prism v4 - Silverlight 4
May 9, 2011 at 3:41 PM

I found if views or viewmodels implement IRegionMemberLifetime, always return KeepAlive to false, will cause RegionContext lost when navigate between views or viewmodels.

May 9, 2011 at 9:06 PM


We checked Prism’s code and found that this is a bug in the Prism Library. The problem you are describing happens because the Region’s region context is being removed from the region itself after a view is removed in it, in response of the KeepAlive property set to false and the view being deactivated.

This happens because, in the BindRegionContextToDependencyObjectBehavior, when a view is removed from a region, the DetachNotifyChangeEvent method is should be called before setting the view’s RegionContext attached property to null, but it’s called after that. Therefore, when setting the view’s RegionContext to null (since it has been removed from the region), the Region Context in the region itself is also set to null, thus causing this unexpected behavior.

We have created a work item in the Issue Tracker to notify the team about this behavior.


Miguel Bronzovic


May 10, 2011 at 1:31 AM

Thank you.

I modify and rebuild the source code, it's ok.

Sep 22, 2011 at 3:17 PM


We created a blog post explaining a possible workaround for this issue, without having to recompile the Prism Library:

Prism v4: RegionContext lost when removing a view from a region

I hope you find this helpful.

Guido Leandro Maliandi