IRegionMemberLifetime interface breaks removing from an itemscontrolregion

Topics: Prism v4 - WPF 4
Feb 17, 2012 at 10:13 AM

IRegionMemberLifetime interface breaks removing from an itemscontrolregion as it seems to try and remove twice, and on the second time error?

So if I have a view attached to a viewmodel that implements that interface and I call something like this:


IRegion region = RegionManager.Regions["itemscontrolregion"];           


It will error.


An example can be found at: called itemscontrol

Feb 23, 2012 at 7:48 PM


Based on my understanding, the problem you are experiencing seems to be the same that the one described in the following thread:

As far as I know, this problems seems to appear when trying to use both the "navigation" functionality and the "view injection" functionality to remove views from a region at the same time. In my opinion, a view / view model that implements the IRegionMemberLifetime interface should usually be removed as a result of being "replaced" by another view through a navigation request, as it might be possible that explicitly removing the view (through the Remove method of the region) might interfere with the "navigation" functionality provided by Prism (for example, if a view / view model have logic implemented in the OnNavigatedFrom method, that logic will not be executed if the view is directly removed from the region).

There is an existing work item in the issue tracking portraying this problem, which includes a possible modification to the ShouldKeepAlive method of the RegionMemberLifetimeBehavior class to avoid this problem:

I hope you find this useful,

Damian Cherubini

Mar 2, 2012 at 7:38 AM

Ok cool thank you.