cristian
cristian

Reputation: 3

remove back button page xamarin xaml

  1. show the page : await Shell.Current.GoToAsync("HabeasData");
  2. in HabeasData constructor I put the following:
     NavigationPage.SetHasBackButton(this, false);
     InitializeComponent();
  1. Too i try this:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             Title="Habeasdata"
             x:Class="AppColantaDomicilios.Views.HabeasData"

      NavigationPage.HasBackButton="False" >

But, it does not work, keep showing the back button.

Xamarin.Forms is updated.

I would greatly appreciate the help.

Upvotes: 0

Views: 2601

Answers (1)

Leon Lu
Leon Lu

Reputation: 9234

NavigationPage.SetHasBackButton(this, false); is not worked in Shell You can use Shell.NavBarIsVisible="False" in the ContentPage like following code.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
            Shell.NavBarIsVisible="False"
             x:Class="App7.Views.Page1">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Here is related article about it.

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/configuration#disable-the-navigation-bar

If you still want to keep the title bar and hide the back button. you can add a custom navigation bar with your stack layout. Or use following code and add a transparent png like following GIF.

enter image description here

Here is code.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"

             x:Class="App7.Views.Page1">
    <Shell.BackButtonBehavior>
        <BackButtonBehavior IsEnabled="False" IconOverride="test.png"
                             />
    </Shell.BackButtonBehavior>

    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Here is transparent png.

enter image description here

Upvotes: 5

Related Questions