user1448108
user1448108

Reputation: 487

How to display TabbedPage in all the screens in Xamarin forms?

I am showing bottom tabs in Xamarin forms using TabbedPage. For that I have added the child pages (Page1,Page2,Page3) programatically to the TabbedPage. First I have login screen, onclick of Login button it will redirect to tabbed page and will show all the three tabs at the bottom.

There are other pages(Page4,Page5) that we are not showing as child pages in tabbed page. But as per the requirement when user opens page4 or page5 the bottom tab bar should show.

Overall what I mean is the bottom tab bar should show to all the screens in the application even though some of the screens are not the children of the TabbedPage.

Could anyone please tell me how to achieve this task. Thanks in advance.

Upvotes: 0

Views: 595

Answers (1)

Mateus Henrique
Mateus Henrique

Reputation: 198

You can wrap TabbedPage's children within NavigationPages, so that when you navigate to another page from one of those tabs they will still appear:

<?xml version="1.0" encoding="UTF-8" ?>
<TabbedPage
    x:Class="SampleTabbedPage.Views.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:views="clr-namespace:SampleTabbedPage.Views;assembly=SampleTabbedPage"
    NavigationPage.HasNavigationBar="False">

    <!-- Page 1 -->
    <NavigationPage IconImageSource="ic_home">
        <x:Arguments>
            <views:HomePage />
        </x:Arguments>
    </NavigationPage>

    <!-- Page 2 -->
    <NavigationPage IconImageSource="ic_profile">
        <x:Arguments>
            <views:ProfilePage />
        </x:Arguments>
    </NavigationPage>
</TabbedPage>

In code behind:

var tabbedPage = new TabbedPage();
tabbedPage.Children.Add(new NavigationPage(new Page1()));
tabbedPage.Children.Add(new NavigationPage(new Page2()));
tabbedPage.Children.Add(new NavigationPage(new Page3()));

Then you can just call from one of the child pages:

await Navigation.PushAsync(new YourNewPage());

Upvotes: 1

Related Questions