1

I am implementing a Xamarin Forms Mobile application using Prism for Navigation.

Is there a way to retrieve the complete Navigation Stack along with the View Models from Prism?

The requirement is, if the user is in the middle of a workflow and the app is closed, the user should be able to continue the workflow when a new session is started.

So I am trying to periodically save the entire navigation stack to the data base.

FRANCIS
  • 11
  • 2

2 Answers2

1

Prism does not have a separate NavigationStack it maintains. Instead it uses the built-in Xamarin.Forms navigation stack. If you need to peek at the actual nav stack then you can do it from the code-behind of a page. If all you need is to get the current uri path of the current page, you can use the GetNavigationUriPath method .

public static string GetNavigationUriPath(this INavigationService navigationService)
   {
        var currentpage = ((IPageAware)navigationService).Page;

        Stack<string> stack = new Stack<string>();
        currentpage = ProcessCurrentPageNavigationPath(currentpage, stack);
        ProcessNavigationPath(currentpage, stack);

        StringBuilder sb = new StringBuilder();
        while (stack.Count > 0)
        {
            sb.Append($"/{stack.Pop()}");
        }
        return sb.ToString();
    }

https://github.com/PrismLibrary/Prism/blob/master/Source/Xamarin/Prism.Forms/Navigation/INavigationServiceExtensions.cs

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
0

You can now get the absolute navigation path of a page by calling INavigationService.GetNavigationUriPath.

beppe
  • 1
  • 1