问题描述
我有一个 ContentPage
,它作为 Xamarin.Forms.Shell
分配给 ShellContent
类,并要求在 ContentPage
的导航栏中显示后退按钮。
关注的 ContentPage
的 XAML 来源如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="UI_test.TestPage">
<Shell.NavBarIsVisible>True</Shell.NavBarIsVisible>
<Shell.BackButtonBehavior>
<BackButtonBehavior IsEnabled="True" />
</Shell.BackButtonBehavior>
<Shell.FlyoutBehavior>disabled</Shell.FlyoutBehavior>
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterandExpand"
HorizontalOptions="CenterandExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
我发现为 TextOverride
标签的 IconOverride
和 <BackButtonBehavior>
属性分配自定义值会显示后退按钮,但我正在寻找一种方法来显示平台的默认后退按钮(而不是自定义按钮),因为上面的 ContentPage
未在其导航栏中显示为后退按钮,如下面的屏幕截图所示。
提前致谢。
解决方法
你的项目好像只有一页,如果没有导航就不会出现,这是有道理的。如果您执行 Shell.GotoAsync(..)
或 Shell.Navigation.PushAsync(..)
以导航到另一个页面,它将出现(默认的原生后退按钮),允许返回导航堆栈中的上一页。