删除后退按钮页面xamarin xaml

0 xaml xamarin

  1. 显示页面: await Shell.Current.GoToAsync("HabeasData");
  2. 在 HabeasData 构造函数中,我输入了以下内容:
     NavigationPage.SetHasBackButton(this, false);
     InitializeComponent();
Run Code Online (Sandbox Code Playgroud)
  1. 我也尝试这个:
<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" >
Run Code Online (Sandbox Code Playgroud)

但是,它不起作用,继续显示后退按钮。

Xamarin.Forms 已更新。

我将非常感谢您的帮助。

Leo*_*SFT 5

NavigationPage.SetHasBackButton(this, false);不适用于Shell 您可以Shell.NavBarIsVisible="False"ContentPage类似以下代码中使用。

<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>
Run Code Online (Sandbox Code Playgroud)

这是有关它的相关文章。

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

如果您仍然想保留标题栏并隐藏后退按钮。您可以使用堆栈布局添加自定义导航栏。或者使用下面的代码并添加一个透明的png,如下面的GIF。

在此输入图像描述

这是代码。

<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>
Run Code Online (Sandbox Code Playgroud)

这是透明的png。

在此输入图像描述