Xamarin.Forms Shell选项卡仅显示列表中的最后一个选项卡

时间:2019-06-01 15:43:04

标签: c# xaml xamarin xamarin.forms

我将现有代码迁移到Xamarin Forms 4.0 Shell,以前我使用的是TabbedPage,但现在我想使用Shell Tabs。

下面是代码在迁移后的样子。我注意到的是,它仅显示一个顶部标签,该标签在列表中具有最后一个条目。就我而言,它仅显示Tab2。

<Shell xmlns="http://xamarin.com/schemas/2014/forms"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      xmlns:views="clr-namespace:App.Views.Tabs;assembly=App"
      x:Class="App.Views.AppShell"
      x:Name="self">
  <TabBar>
       <Tab>
            <ShellContent>
              <views:Tab1Page BindingContext="{x:Reference self}" Title="Tab1" />
              <views:Tab2Page BindingContext="{x:Reference self}" Title="Tab2"/>
            </ShellContent>
        </Tab>
   </TabBar>

</Shell>

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

<Shell>
...   
   <Tab>
        <ShellContent Title="Tab1">  <!-- title in the tab -->
            <views:Tab1Page} Title="Tab1" BindingContext="{x:Reference self}"/>
                        <!-- Title in the navigation bar -->
        </ShellContent>
        
        <ShellContent Title="Tab2">
            <views:Tab2Page} Title="Tab2" BindingContext="{x:Reference self}"/>
        </ShellContent>
    </Tab>
...
</Shell>

Microsoft文档

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/tabs