How to hide the arrow back in Xamarin?

Asked

Viewed 265 times

1

In my mobile application I wouldn’t want there to be an option to go back to the home page, because if I do this, the person goes back to the login screen. How do I remove this arrow just from this page?

1 answer

1


In XAML you can hide the button through Attachedproperty HasBackButton of NavigationPage thus:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SeuNamespace.Views"
             x:Class="SeuNamespace.Views.SuaPage"
             NavigationPage.HasBackButton="False">
    <!-- Conteúdo da sua página -->
</ContentPage>

In the codebehind it would be like this:

namespace SeuNamespace.Views 
{
    public partial class SuaPage : ContentPage
    {
        public SuaPage()
        {
            InitializeComponent();
            NavigationPage.SetHasBackButton(this, false);
        }
    }
}

Remember that there will always be the possibility for the user to use the back button of the hardware. In this case, you can deal with overriding the handler of the corresponding event via the method OnBackButtonPressed of the returning page true. Thus:

protected override bool OnBackButtonPressed()
{
    // Alguma lógica de tratamento
    return true;
}
  • Really I did similarly yesterday and it worked... Anyway thank you very much!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.