meetme
meetme

Reputation: 203

NavigationPage as a child of a TabbedPage in XAML

I am trying to find a way to add a NavigationPage be a child of a TabbedPage in XAML. Adding xaml for NavigationPage doesn't work for me. In my code, GetMainPage() returned page is a TabbedPage XAML, and it has children, which are also described in XAML, how can I insert a NavigationPage programmatically in between the XAML?

Following is my code:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   <ContentPage x:Name="FirstTab" Title="Music">
      <StackLayout Padding="5, 25">
          ...
      </StackLayout>
   </ContentPage>-->
   <ContentPage x:Name="SecondTab" Title="Videos">
      <StackLayout Padding="5, 25">
          ...
      </StackLayout>
   </ContentPage>-->
   <ContentPage x:Name="ThirdTab" Title="Movies">
      <StackLayout Padding="5, 25">
          ...
      </StackLayout>
   </ContentPage>-->
</TabbedPage>

And in App.cs

public App()
{
        // The root page of your application
        MainPage = new NavigationPage(new TabbedMainPage());
}

Upvotes: 2

Views: 3414

Answers (2)

Morse
Morse

Reputation: 9115

Now we can add a NavigationPage as child of TabbedPage in XAML as well.

<?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="Views.TabbedMainPage"
            xmlns:ent="clr-namespace:Views.Entertainment">
    <ent:Music />
    <NavigationPage Title="Videos">
        <x:Arguments>
            <ent:Videos />
        </x:Arguments>
    </NavigationPage>
    <ent:Movies />
</TabbedPage>

Reference :
Microsoft:Xamarin:TabbedPage
Github:TabbedPageWithNavigationPage

Upvotes: 1

Jason
Jason

Reputation: 89082

You can't really add a NavigationPage in XAML - it doesn't have an exposed Content property you can use to assign Children. However, it is easy to do in code:

var tabs = new TabbedPage();

tabs.Children.Add(new NavigationPage(new Page1()));
tabs.Children.Add(new NavigationPage(new Page2()));
tabs.Children.Add(new NavigationPage(new Page3()));

Upvotes: 2

Related Questions