Forum Xamarin.Forms

Page.OnBackButtonPressed support for software back button

JeremyHerbisonJeremyHerbison CAMember ✭✭
edited January 2017 in Xamarin.Forms


Developers can override the OnBackButtonPressed method to opportunistically cancel back navigation via the hardware back button. The back button, though, is Android-specific (and WP?) and doesn't apply to back navigation via software, such as the navigation bar. This leaves it counter-intuitive, platform-specific, and ultimately not that useful.

API Changes

I would propose adding a different method,

protected virtual bool OnBackNavigation(bool fromBackButton)

where fromBackButton indicates if it was the hardware button or some other method (ie the navigation bar). You could then mark the old API as obsolete.

Intended Use Case

Intercepting back navigation is useful when you want to confirm that the user really wants to cancel, or potentially save any changes before backing out. Without such functionality, you need to navigate modally, implement your own "Cancel" button (which doesn't look native, because you can't place it on the left side given toolbaritem limitations) and then also override OnBackButtonPressed for Android. This change would make things much simpler, and allow for a more native look and feel.


Open · Last Updated


Sign In or Register to comment.