Dimitris
Dimitris

Reputation: 755

Xamarin Forms - Prism detect GoBack

Using Xamarin.Forms v4.5 and Prism v7.2

I have an APP with 3 pages (PageA, PageB and PageC).

From PageA, I can navigate to PageB and from PageB to PageC. From PageC, I can tap on the back button and go back to PageB.

My question is, when I navigate to PageB (either from PageA or PageC), is there a method that Prism provides to identify whether I end up to PageB by pressing the back button?

Upvotes: 1

Views: 1208

Answers (1)

Dan Siegel
Dan Siegel

Reputation: 5799

At this time Xamarin.Forms does not provide a way to hook into the underlying Navigation Service and intercept the full Navigation process in certain flows such as when someone clicks on a hardware back button. As a result we are limited in what we can do and are therefore not able to support IConfirmNavigation to allow you to prevent navigating away.

That having been said we are able to observe that a Page was popped and we are still able to invoke OnNavigatedFrom/OnNavigatedTo. You can easily determine what has occurred by getting the NavigationMode. To do this your code might look like this:

public void OnNavigatedTo(INavigationParameters parameters)
{
    var mode = parameters.GetNavigationMode();
    switch(mode)
    {
        case NavigationMode.New:
            break;
        case NavigationMode.Back:
            break;
        case NavigationMode.Forward:
            break;
    }
}

Upvotes: 6

Related Questions