VVK
VVK

Reputation: 11

Xamarin forms - Prism GoBackToRootAsync with parameters

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.

Upvotes: 1

Views: 732

Answers (1)

Hamid Shaikh
Hamid Shaikh

Reputation: 197

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;
}

Upvotes: 1

Related Questions