[英]How can I hide the back button from certain pages in the shell?
僅在login
和notifications
頁面上,我希望用戶無法返回上一頁。 在所有其他頁面上,該過程可以正常進行。
到目前為止,我只能使用BackButtonBehavior IsEnabled = "False"
禁用按鈕單擊操作。
NotificationsPage.xaml和LoginPage.xaml
<Shell.BackButtonBehavior>
<BackButtonBehavior IsEnabled="False"/>
</Shell.BackButtonBehavior>
令牌視圖模型
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));
這是一種解決方法。您可以隱藏整個導航欄,然后使用 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.