如何隐藏 shell 中某些页面的后退按钮?

Jos*_*rme 5 c# xaml android xamarin.forms xamarin.forms.shell

仅在loginnotifications页面上我希望用户无法返回到上一页。在所有其他页面上,该过程可以正常进行。

\n

到目前为止,我只能使用 禁用按钮单击操作BackButtonBehavior IsEnabled = "False"

\n

NotificationsPage.xamlLoginPage.xaml

\n
<Shell.BackButtonBehavior>\n        <BackButtonBehavior IsEnabled="False"/>\n</Shell.BackButtonBehavior>\n
Run Code Online (Sandbox Code Playgroud)\n

后退箭头按钮在导航栏中可见

\n

令牌视图模型

\n
await Shell.Current.GoToAsync($"{nameof(NotificacoesPage)}");\n
Run Code Online (Sandbox Code Playgroud)\n

应用程序.xaml.cs

\n
await Shell.Current.GoToAsync($"{nameof(NotificacoesPage)}", false);\n
Run Code Online (Sandbox Code Playgroud)\n

AppShell.xaml

\n
<TabBar>\n        <Tab Icon="notificacao_icone.png"\n             Title="Notifica\xc3\xa7\xc3\xb5es">\n            <ShellContent ContentTemplate="{DataTemplate local:NotificacoesPage}" />\n        </Tab>\n\n        <Tab Icon="configuracoes_icone.png"\n             Title="Configura\xc3\xa7\xc3\xb5es">\n            <ShellContent ContentTemplate="{DataTemplate local:ConfiguracoesPage}" />\n        </Tab>\n</TabBar>\n
Run Code Online (Sandbox Code Playgroud)\n

AppShell.xaml.cs

\n
Routing.RegisterRoute(nameof(LoginPage), typeof(LoginPage));\nRouting.RegisterRoute(nameof(TokenPage), typeof(TokenPage));\nRouting.RegisterRoute(nameof(NotificacoesPage), typeof(NotificacoesPage));\nRouting.RegisterRoute(nameof(NotificacaoDetalhePage), typeof(NotificacaoDetalhePage));\nRouting.RegisterRoute(nameof(ConfiguracoesPage), typeof(ConfiguracoesPage));\n
Run Code Online (Sandbox Code Playgroud)\n

Leo*_*SFT 2

这是一个解决方法。您可以隐藏整个导航栏,然后使用 StackLayout 自定义一个导航栏来代替它。

就像是:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ShellNewDemo.Views.ItemDetailPage"
         Shell.NavBarIsVisible="False"   //hide the navigationbar
         >

  <ContentPage.Content>

      <StackLayout Orientation="Vertical">

        <StackLayout Orientation="Horizontal">

            //define your custom navigationbar

        </StackLayout>
        <StackLayout Orientation="Vertical">

           //content

        </StackLayout>

      </StackLayout>
    
  </ContentPage.Content>

</ContentPage>
Run Code Online (Sandbox Code Playgroud)