Reputation: 11
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.
Upvotes: 1
Views: 1135
Reputation: 1
You can now get the absolute navigation path of a page by calling INavigationService.GetNavigationUriPath.
Upvotes: 0
Reputation: 12723
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();
}
Upvotes: 1