Xamarin形成多个NavigationPages

问题描述

我有问题。在我的应用中,我具有以下结构

  • NavigationPage(根)

现在,我想从TabbedPage内部的页面转到带有Navigation.PushAsync()的另一页面,但是当我这样做时,我会在屏幕上显示TabbedPageBar的新页面。那不是我想要的,我想使用根NavigationPage转到另一页,所以当单击返回时,我回到NavigationPage内的TabbedPage

以下是一些代码
App.xaml.cs:

MainPage = new NavigationPage (new MainPage());

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:d="http://xamarin.com/schemas/2014/forms/design"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:views="clr-namespace:MyApp.Views"
            mc:Ignorable="d"
            x:Class="MyApp.Views.MainPage"
            xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
            android:TabbedPage.ToolbarPlacement="Bottom"
            BarBackgroundColor="White"
            BarTextColor="Black"
            android:TabbedPage.BarItemColor="#B2B2B2"
            android:TabbedPage.BarSelectedItemColor="#56D7A5"
            android:TabbedPage.IsSwipePagingEnabled="False">    

    <TabbedPage.Children>
        <NavigationPage Title="Page1" IconImageSource="navbar_page1">
            <x:Arguments>
                <views:page1 NavigationPage.HasNavigationBar="False" />
            </x:Arguments>
        </NavigationPage>
    </TabbedPage.Children> 
</TabbedPage>

page1.xaml.cs:

private void OpenPage()
{
    Navigation.PushAsync(new page2());
}

因此,很明显,我现在得到的结果是page2具有TabbedPageBar,所以我需要使用根目录的NavigationPage,所以TabbedPageBar会消失,但我不知道该怎么做。

有人可以帮我吗

解决方法

将选项卡式页面放在NavigationPage中不是一个好的设计,它在应用程序中将有两个导航栏。

只需将选项卡式页面直接设置为MainPage。

MainPage = new MainPage();