1

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

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

NotificationsPage.xamlLoginPage.xaml

<Shell.BackButtonBehavior>
        <BackButtonBehavior IsEnabled="False"/>
</Shell.BackButtonBehavior>

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

令牌视图模型

await Shell.Current.GoToAsync($"{nameof(NotificacoesPage)}");

应用程序.xaml.cs

await Shell.Current.GoToAsync($"{nameof(NotificacoesPage)}", false);

AppShell.xaml

<TabBar>
        <Tab Icon="notificacao_icone.png"
             Title="Notificações">
            <ShellContent ContentTemplate="{DataTemplate local:NotificacoesPage}" />
        </Tab>

        <Tab Icon="configuracoes_icone.png"
             Title="Configurações">
            <ShellContent ContentTemplate="{DataTemplate local:ConfiguracoesPage}" />
        </Tab>
</TabBar>

AppShell.xaml.cs

Routing.RegisterRoute(nameof(LoginPage), typeof(LoginPage));
Routing.RegisterRoute(nameof(TokenPage), typeof(TokenPage));
Routing.RegisterRoute(nameof(NotificacoesPage), typeof(NotificacoesPage));
Routing.RegisterRoute(nameof(NotificacaoDetalhePage), typeof(NotificacaoDetalhePage));
Routing.RegisterRoute(nameof(ConfiguracoesPage), typeof(ConfiguracoesPage));
4

1 回答 1

1

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

就像是:

<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>
于 2021-02-23T06:35:44.630 回答