I am trying to pass parameters back to a view using GoBackAsync()
. All my view modelas inherit a BaseViewModel
which inherits INavigatedAware
.
The navigation path to the last page where I go back is as follows:
NavigationPage/TabbedView -> ViewA -> ViewB -> ViewC
ViewC is a ListView
and when I select an item from the view GoBackAsync()
is called passing the item object
back to the previous view.
Actual Behaviour:
When GoBackAsync()
is called I am taken from ViewC to ViewB to ViewA.
Expected Behaviour:
When GoBackAsync()
is called I land on View B from View C.
ViewAViewModel
private async void ViewAToViewB()
{
await _navigationService.NavigateAsync("ViewB", useModalNavigation:false);
}
ViewBViewModel
private async void ViewAToViewC()
{
await _navigationService.NavigateAsync("ViewC", useModalNavigation:false);
}
public override void OnNavigatedTo(INavigationParameters parameters)
{
if (parameters.Count > 0)
{
var myString = parameters.GetValue<string>("testParam");
}
}
ViewCViewModel
private async void NavigateBackToViewB()
{
var navigationParams = new NavigationParameters();
navigationParams.Add("testParam", "Adam Sandler");
await _navigationService.GoBackAsync(navigationParams, useModalNavigation:false);
}
Temporary fix
In ViewAViewModel.cs
I have had to prefix ViewB with NavigationPage/ and then set ViewB.xaml and ViewC.xaml to have NavigationPage.HasNavigationBar = false
to stop 2 navigations bars showing.
This is the only way my GoBackAsync()
goes to ViewB from ViewC and not all the way back to ViewA.