Forum Cross Platform with Xamarin

How to show confirmation dialog before popping a Page ?

I am developing a cross platform application. It has two pages say A and B.
From A I use Navigation.PushAsync to move to page B.

In the Toolbar, at the top of the screen, I have the back button. (Back in case of iOS and Home button as Up in case of android).
On pressing that back button, I need a dialog asking for confirmation, whether the user is sure to go to previous screen.
Only if the user presses ok, the current Page has to be popped.

How can this be done ?

Note : The onBackButtonPressed() method is called in Android, only if the user presses the android back key and not the home in Toolbar.
In iOS, it is not at all called.


  • adamkempadamkemp USInsider, Developer Group Leader mod

    This sounds like a Xamarin.Forms question so it probably belongs in that forum.

    Short answer: don't have a back button. On iOS there are multiple ways of going back in a navigation stack, and the button is just one. You could also swipe either in the toolbar or from anywhere on the left edge of the screen (and those are two different gesture handlers). Trying to stop the user from going back is awkward at best, and confusing to the user.

    If you don't want someone to be able to go back then don't have a back button at all. You do that by presenting the first page modally instead. Like this:

    Navigation.PushModalAsync(new NavigationPage(new FirstPage()));

    Then you can provide a toolbar button for "Done", and do your confirmation in the handler for that button.

Sign In or Register to comment.