TBA
TBA

Reputation: 1187

Xamarin - How can I call a TabbedPage

I am currently learning Xamarin development, looks like quite a big learning curve.

Well I have a tabbed page class (TabbedPageTest.cs) which I inherited from TabbedPage.

Now how can I just view that page.

Let's say I wanted to navigate using a cell from a table view.

TableView tb = new TableView
                {
                    Intent = TableIntent.Menu,
                    Root = new TableRoot
                    {
                        new TableSection("Tabbed Page Test")
                        {
                            new TextCell
                            {
                              // What all codes can I add here to navigate or view TabbedPageTest.cs?
                            }
                        }
                    }
                 }

Upvotes: 0

Views: 1917

Answers (3)

Nirav Mehta
Nirav Mehta

Reputation: 7063

//Tabbed Page Demo Code to be used in PCL for Xamarin.Forms

    TabbedPage tabs = new TabbedPage ();

    tabs.Children.Add(
        new NavigationPage (new MainPage () { Title = "Title for MainPage" }) {
            Title = "Tile for TabbedPage Tab1" // Add this title for your TabbedPage
        }
    );

    tabs.Children.Add(
        new NavigationPage (new FirstPage () { Title = "Title for FirstPage" }) {
            Title = "Tile for TabbedPage Tab2" // Add this title for your TabbedPage
        }
    );
    return  tabs;

Hope this helps

Upvotes: 2

Jesse Liberty
Jesse Liberty

Reputation: 1414

You asked for the code in C#. Here you go...

public partial class MainPage : TabbedPage    // Note inherits from TabbedPage
{
    public MainPage ( )
    {
        this.Title = "Tabbed Page Demo";
        var appliancePage = new AppliancePage ( );
        var helpPage = new HelpPage ( );
        this.Children.Add( appliancePage );
        this.Children.Add( helpPage );
    }
}

The above is in MainPage.cs. MainPage.xaml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"   <!-- note TabbedPage -->
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
x:Class="XamlToCSharpDemo.MainPage">
</TabbedPage>

Remember that each child page (e.g., HelpPage) must have a title...

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
x:Class="XamlToCSharpDemo.HelpPage" Title="Help">   <!-- Note Title -->
  <ContentPage.Content>
    <Label Text="Help Page"/> 
  </ContentPage.Content>
</ContentPage>

Upvotes: 2

Jesse Liberty
Jesse Liberty

Reputation: 1414

Here is my code for a tabbed page in Xamarin Forms...

    <?xml version="1.0" encoding="UTF-8"?>
   <TabbedPage 
   xmlns="http://xamarin.com/schemas/2014/forms" 
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
   xmlns:me="clr-namespace:EvalUate;assembly=EvalUate"   
   x:Class="EvalUate.MainPage"
   Title="EvalUate">
    <TabbedPage.Children>
        <me:AppliancePage />
        <me:HelpPage />
        <me:LicensePage />
    </TabbedPage.Children>
   </TabbedPage>

With that in place, no code is needed, it will find the correct page.

Upvotes: 2

Related Questions