1

I am trying to pass navigation parameters with the GoBackToRootAsync(navParams) method in Prism. But it doesn't seem to work. Is this really supported by this method? Has anyone got it working? It works fine with other navigation service methods.

LeRoy
  • 4,189
  • 2
  • 35
  • 46
VVK
  • 11
  • 1
  • Why don't use the absolute navigation? (/Page) – Jesus Angulo Feb 26 '18 at 18:57
  • @JesusAngulo Yes, thats an option. Ty. But I wanted to understand if anyone got it working with this particular method in Prism. – VVK Feb 26 '18 at 19:17
  • Firstly, you need to tell us what kind of layout/navigation patterns you've implemented – Jesus Angulo Feb 26 '18 at 19:18
  • 1
    My app is a tabbed page application that relies completely on Prism navigation services. Using the absolute URI resets the stack and the value in the root view gets lost which is not my requirement. Say I have a navigation stack like Root-->A-->B. I want to pass some value from B to the root using the GoBackToRootAsync method. Let me know if you were able to achieve it this way. – VVK Feb 26 '18 at 19:30

1 Answers1

1

Yes, I can confirm it works like charm. Please find the below steps

NavParameters.Add(nameof(SelectedMyItemsList), SelectedMyItemsList);
await NavigationService.GoBackAsync(NavParameters);

Now you can receive it like below in your previous page view model inside OnNavigated method

public override void OnNavigatedTo(NavigationParameters parameters)

var navMode = (NavigationMode)parameters[KnownNavigationParameters.NavigationMode];
switch (navMode)
{
    case NavigationMode.New:
    //Your code
    break;
    case NavigationMode.Back:
    if (parameters.ContainsKey(nameof(SelectedMyItemsList)))
    {
       SelectedMyItemsList = parameters[nameof(SelectedMyItemsList)] as List<ItemModel>;
    }
    break;
}
Hamid Shaikh
  • 197
  • 6