简体   繁体   English

Xamarin.Forms:如何在整个应用程序中获取选项卡式页面

[英]Xamarin.Forms: How to get Tabbed Page throughout the app

I need to have TabbedPage throughout the app. 我需要在整个应用程序中都具有TabbedPage In the first page Tab's are displaying fine. 在第一页中,选项卡显示正常。 When I am starting second page From Tab1, It is hiding all tabs. 当我从Tab1开始第二页时,它正在隐藏所有选项卡。 How can I have Tab's all over the app. 如何在整个应用程序中使用Tab。

带标签的首页 没有标签的第二页

MainPage.xaml 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"
             x:Class="TabbedApp.MainPage"
             xmlns:local="clr-namespace:TabbedApp">
    <local:DairyTabs></local:DairyTabs>
    <ContentPage Title="Tab 2">
        <StackLayout>
            <Label Text="Tab 2"   
            HorizontalTextAlignment="Center"  
            HorizontalOptions="FillAndExpand"  
            Margin="5" />
        </StackLayout>
    </ContentPage>
</TabbedPage>

This is the code from starting 2nd page 这是从第二页开始的代码

btnDemo.Clicked +=async delegate {
                await Navigation.PushModalAsync(new Page2());
            };

I need to have TabbedPage throughout the app 我需要在整个应用程序中使用TabbedPage

You must add a NavigationPage as a child page in your TabbedPage in order to open pages inside the tab 您必须在TabbedPage中添加NavigationPage作为子页面,以便在选项卡中打开页面

So in your Xaml, you can have a NavigationPage inside TabbedPage 因此,在您的Xaml中,您可以在TabbedPage中包含一个NavigationPage

<TabbedPage  xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TabbedApp.MainPage"
             xmlns:local="clr-namespace:TabbedApp">
    <local:PageA/>
    <NavigationPage Title="Your Title">
        <x:Arguments>
            <local:MyPage />
        </x:Arguments>
    </NavigationPage>
</TabbedPage>

Then you can add pages like this 然后您可以添加这样的页面

public class MainPageCS : TabbedPage{
    public MainPageCS ()
    {
        var navigationPage = new NavigationPage (new MyPage ());

        navigationPage.Title = "Your title";

        Children.Add (new PageA ());
        Children.Add (navigationPage);
    }
}

So Navigation can be performed from this second page which is a instance of NavigationPage, like below 因此,可以从第二页(作为NavigationPage的实例)执行导航,如下所示

async void OnSomeButtonClicked (object sender, EventArgs e)
{
  await Navigation.PushAsync (new Page2());
}

More info in this here 更多信息在这里

Try to use: 尝试使用:

Navigation.PushAsync(new Page2());

Instead of: 代替:

Navigation.PushModalAsync(new Page2());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM