1

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.

steve
  • 797
  • 1
  • 9
  • 27
  • how are you navigating to view A and view B – ebk Aug 19 '19 at 14:47
  • @ebk that has been added to the question now! let me know if anything else is required, thanks. – steve Aug 19 '19 at 14:52
  • we need your whole ViewBViewModel code – Roubachof Aug 20 '19 at 09:24
  • Kindly share TabbedView (ViewModel) code...As it is important to understand how you are navigating from TabbedView > ViewA – Hamid Shaikh Sep 10 '19 at 08:09
  • Any chance solving this ? I have more or less the same issue and i can't seem to fix this behaviour, not even by using the app NavigationPage/ as suffix – Stefano Driussi Oct 03 '19 at 14:38
  • 1
    @StefanoDriussi instead of using `NavigationPage/TabbedView` I wrapped each `TabPage` child element in a `NavigationPage` that should give your more control not over navigation but also title and icons for each of your tab views. – steve Oct 08 '19 at 23:21
  • @steve thanks for the reply. In the end i've done something similar to your suggestion and it works. Still i don't get why if i create a totally new app with the same hierarchy, back navigation works as expected. – Stefano Driussi Oct 11 '19 at 09:04

0 Answers0