Feb 20, 2012 at 11:32 AM

Hi List,

if i correctly understand the documentation for IRegionMemberLifetime Interface then an view and the correspondening ViewModel should be disposed if KeepAlive is set to false.

What i have:

add ViewA-ViewModelA to Region set KeepAlive = false; -> View is removed from Region

Show another ViewB_ViewModelB

Show ViewA_ViewModelA again                                    -> Constructor of ViewA and ViewModelA isn't called again

but the View is added to the region.

Is ther aomething wrong with my idea?









Feb 21, 2012 at 3:12 PM

Peter, are you using Unity or MEF? If using MEF, what PartCreationPolicy attributes are you using on your View and ViewModel? I think you need to use CreationPolicy.NonShared. Also, are you using RequestNavigate to navigate to your views or are you using RegisterViewWithRegion. If using RequestNavigate, what code do you have in IsNavigationTarget?

Feb 22, 2012 at 9:18 AM

Hi Pedro,

i'm using MEF.

The Exports of my ViewModels are definied as follows:

 public class UserControl2ViewModel : IUserControl2ViewModelINavigationAware,IRegionMemberLifetime
public bool IsNavigationTarget(NavigationContext navigationContext)
            logger.Log(String.Format("Model2 - IsNavigationTarget <{0}>", navigationContext.Uri), Category.Info, Priority.Low);
            return true;
 public bool KeepAlive
                logger.Log("Model2 - KeepAlive",Category.Info, Priority.Low);
                return false;
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl

The Constructor UserControlXY and UserControlXYViewmodel are called only once when i'm navigation to the View/Model the first time,

for all usages of the Views/ViewModels there is no more Constructor call.


Feb 22, 2012 at 6:54 PM

I think you will also need PartCreationPolicy.NonShared on your views. I also think you need to return false in IsNavigationTarget. As far as I understand, if you return true you are saying the existing viewmodel instance can deal with the navigation request. If you return false, a new viewmodel/view should get created and the old one should then get disposed.

There is a useful diagram showing the navigation flow here:

Hope this helps - I've been through the pain!

Feb 23, 2012 at 5:58 AM

Hi pedro,

you are right, the problem was the PartCreationPolicy.NonShared Attribute in View and ViewModel

I got it to work

Thanks for the help