简体   繁体   中英

Xamarin.Forms Shell Tabs only showing last Tab in the list

I am migrating my existing code to Xamarin Forms 4.0 Shell , Previously I was using TabbedPage but now I want to use Shell Tabs.

Below is what the code looks like after migration. What I noticed is that it's only showing one top tab which has last entry in the list. In my case, it's showing Tab2 only.

<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>

Try with the following code:

<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 Documentation

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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