【问题标题】:How can I hide the back button from certain pages in the shell?如何隐藏外壳中某些页面的后退按钮?
【发布时间】:2021-05-21 18:34:34
【问题描述】:

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

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

NotificationsPage.xamlLoginPage.xaml

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

TokenViewModel

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

App.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));

【问题讨论】:

  • 用户填写login字段并填写token字段后,将被定向到notifications页面(打印上的那个)。通过下方菜单,他可以访问settings 页面,在那里他可以删除他的帐户(这会将他带到login 页面以再次填写字段)。
  • 两者都使用 gotoasync
  • modal navigation 适合你吗?
  • 这是一个已知的issue,已移至to do block
  • @Shaw 我将无法使用模态导航,因为我需要在Shell.TitleView 中显示应用程序的徽标。

标签: c# android xaml xamarin.forms xamarin.forms.shell


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2012-05-15
    相关资源
    最近更新 更多