Disable device back button RRS feed

  • Question

  • User352971 posted

    Hi all.

    Any one know how to disable device back button in xamarin forms app?

    Thanks Lasantha

    Tuesday, January 16, 2018 11:23 PM

All replies

  • User89714 posted

    @LasanthaPW - See https://xamarinhelp.com/xamarin-forms-back-navigation-pitfalls/

    (there are also many threads in the forum about this already)

    Tuesday, January 16, 2018 11:48 PM
  • User180523 posted

    In short you can't disable it. You can however simply intercept it. Just handle the OnBackButton event, mark it as handled, then don't do anything.

    @JohnHardman is right too. Most anything you could ask a question about in these early stages of you learning Xamarin has already been asked by someone before you. Probably several times. If you search the site you'll probably find 10 threads for anything you could imagine: Meaning you'll get a more complete answer faster by just reading the existing threads than composing a new question and waiting for a response.

    Wednesday, January 17, 2018 12:34 PM
  • User368052 posted

    in Xamarin forms for android use dis code protected override bool OnBackButtonPressed() { return true; }

    for iOS no hardware back button but soft button u can disable in UI, use dis in the content page NavigationPage.HasBackButton="False"

    Friday, August 3, 2018 7:13 AM
  • User342691 posted

    YES! works for me on Xamarin.Forms using only Android. BUT, just to pass along, I had a hard time realizing that this is in the context of the Page class -- because I had an override of void OnBackPressed() in MainActivity.cs

    So I kept assuming that context, but could not figure out why I had a void function and how I could return true.

    Anyway, thank you all very much!

    Friday, October 12, 2018 4:26 PM
  • User387169 posted

    It is possible to disable the back button in Xamarin.Forms.ContentPage:

    ```csharp public class MyPage : ContentPage { //...

    protected override bool OnBackButtonPressed() => false;

    } ```

    Sunday, July 7, 2019 9:04 AM
  • User395370 posted

    I had the same problem. I solved it by below code. You can paste it in which page you need:

    protected override bool OnBackButtonPressed() => true;

    Wednesday, June 24, 2020 12:17 PM