Problem with view model instance preservation when navigating back using navigator extension #2034
-
I'm working on an application using Uno Platform and facing a problem with navigation between ViewModels. My application includes two ViewModels, named ViewModelA and ViewModelB. I use the INavigator service for navigation from ViewModelA to ViewModelB. However, when I navigate back to ViewModelA using the Example Code: // Navigation from ViewModelA to ViewModelB
public class ViewModelA : ViewModelBase
{
private readonly INavigator _navigator;
public ViewModelA(INavigator navigator)
{
_navigator = navigator;
}
public void NavigateToViewModelB()
{
_navigator.NavigateRouteAsync(this, "ViewModelB");
}
}
// Navigation back to ViewModelA
public class ViewModelB : ViewModelBase
{
private readonly INavigator _navigator;
public ViewModelB(INavigator navigator)
{
_navigator = navigator;
}
public void NavigateBack()
{
_navigator.NavigateBackAsync(this);
}
} In this scenario, I use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @LITTOMA I think you need to set NavigationCacheMode on PageA to required. What's happening is the page is getting recreated (instead of a cached version being used), so you get a new instance of the viewmodel. |
Beta Was this translation helpful? Give feedback.
Hi @LITTOMA I think you need to set NavigationCacheMode on PageA to required. What's happening is the page is getting recreated (instead of a cached version being used), so you get a new instance of the viewmodel.
Let me know if this fixes your issue