I'm building a Windows 8.1 mobile app with MVVMCross and I noticed some strange behavior when navigating between viewmodels.
I have 2 Viewmodels like so...
public class FirstViewModel : MvxViewModel
{
public override void Start()
{
base.Start();
}
public void Init()
{
//init code here
}
...
private void GoForward()
{
ShowViewModel<SecondViewModel>();
}
}
public class SecondViewModel : MvxViewModel
{
private void GoBack()
{
Close(this);
}
}
When I call Close(this) on SecondViewModel, Mvvmcross calls Start() and Init() on FirstViewModel again, like it was tombstoned.
Why does this happen? Even if I only leave FirstViewModel for a couple seconds, it seems to be tombstoned immediately. How do I stop this from happening? It's frustrating because I now have to maintain the state of FirstViewModel constantly.
You need to write the following line of code in your page constructor. This enables the caching of visited pages.
NavigationCacheMode = NavigationCacheMode.Required;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With