【问题标题】:Xamarin.Forms: How to get Tabbed Page throughout the appXamarin.Forms:如何在整个应用程序中获取选项卡式页面
【发布时间】:2018-03-15 20:10:38
【问题描述】:

我需要在整个应用程序中使用TabbedPage。在第一页选项卡的显示正常。当我从 Tab1 开始第二页时,它隐藏了所有选项卡。我怎样才能在整个应用程序中都有 Tab。

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>

这是从第二页开始的代码

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

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    我需要在整个应用程序中使用 TabbedPage

    您必须在 TabbedPage 中添加 NavigationPage 作为子页面才能在选项卡内打开页面

    所以在您的 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>
    

    然后你可以添加这样的页面

    public class MainPageCS : TabbedPage{
        public MainPageCS ()
        {
            var navigationPage = new NavigationPage (new MyPage ());
    
            navigationPage.Title = "Your title";
    
            Children.Add (new PageA ());
            Children.Add (navigationPage);
        }
    }
    

    所以可以从作为 NavigationPage 实例的第二个页面执行导航,如下所示

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

    更多信息在here

    【讨论】:

    • PageAMyPage 有什么区别。 PageANavigationPage 之外,MyPage 在里面。
    • 这里PageA是你的第一个标签,它是ContentPage,第二个标签是MyPage,这是一个NavigationPage,它允许你在这个标签内打开另一个页面
    • 好的,当我们转到第二个选项卡时(MyPage)它刚刚开始在顶部显示导航栏。除了没有改变任何东西。
    • 哎呀,这里MyPage 也必须是ContentPage
    【解决方案2】:

    尝试使用:

    Navigation.PushAsync(new Page2());

    代替:

    Navigation.PushModalAsync(new Page2());

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      相关资源
      最近更新 更多