【问题标题】:Displaying the default back button of the navigation bar of a ContentPage assigned to the Xamarin.Forms Shell显示分配给 Xamarin.Forms Shell 的 ContentPage 导航栏的默认后退按钮
【发布时间】:2021-07-18 21:40:42
【问题描述】:

我有一个ContentPage,它作为ShellContent 分配给Xamarin.Forms.Shell 类,并要求在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>

我发现为&lt;BackButtonBehavior&gt;标签的TextOverride和IconOverride属性分配自定义值会显示返回按钮,但我正在寻找一种显示平台默认返回按钮的方法(而不是一个自定义的)如上面的ContentPage 不会在其导航栏中显示为后退按钮,如下面的屏幕截图所示。

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    您的项目似乎只包含一页,如果没有进行导航,它不会出现,这是有道理的。如果您使用Shell.GotoAsync(..) 或Shell.Navigation.PushAsync(..) 导航到另一个页面,它将出现(默认的本机后退按钮),允许返回导航堆栈中的上一页。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      相关资源
      最近更新 更多