0
votes

Using xamarin forms prism:

My intention is to have the user enter a pw when trying to navigate back from "View3" and allow the navigation only if pw is correct.

I have the following stack: MasterDetail/Navigation1/View1/View2/Navigation2/View3

When i try to navigate from view2 to navigation2, I use modal navigation. So I dont have 2 navbars..

Navigation2 has a custom "exit" button. When pressed, I want to navigate back to View2 so my stack will be: MasterDetail/Navigation/View1/View2

But when I try the following code, nothing happens:

 _navigationService.GoBackAsync(useModalNavigation: false);
 _navigationService.GoBackAsync(useModalNavigation: true);
 _navigationService.GoBackToRootAsync();

And when I use _navigationService.NavigateAsync("MasterDetail/Navigation/View1/View2", useModalNavigation:true); it works but then it re-initialized the views, which i want to avoid.

What could be causing this? Am I doing something wrong? thanks for any input!

1

1 Answers

0
votes

From this PR, you can now use this in Prism 7.1 and prior:

_navigationService.NavigateAsync("../../");

to pop the last 2 pages from the Navigation Stack.

Also you shouldn't have 2 navigation pages in the same stack, i can cause problems with your navigation, i sugest that you turn your View3 into a Modal Page and add a back verification for Android BackPress:

protected override bool OnBackButtonPressed()
{
    if (((MyView3ViewModelPage)BindingContext).ExitCommand != null)
    {
        ((MyView3ViewModelPage)BindingContext).ExitCommand.Execute();
        return true;
    }
    return base.OnBackButtonPressed();
}

And create your own Back Button, since it's a Form and you won't navigate elsewhere from that, you have total control on how you present that page