Reputation: 1397
I have an app I am working on in xamarin forms it looks like this:
When the app loads the friends tab is the 1st tab to load how do I make it to where the snap tab is the 1st tab to load when the app starts up?
Here is my xaml 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"
xmlns:local="clr-namespace:AppName;assembly=AppName"
x:Class="AppName.HomePage">
<TabbedPage.Children>
<NavigationPage x:Name="Friends" Title="Friends" Icon="firendstab.png">
<x:Arguments>
<local:FriendPage />
</x:Arguments>
</NavigationPage >
<NavigationPage x:Name="Snap" Title="Snap" Icon="snaptab.png">>
<x:Arguments>
<local:CameraPage />
</x:Arguments>
</NavigationPage>
<NavigationPage x:Name="Notes" Title="Notes" Icon="notetab.png">
<x:Arguments>
<local:NotePage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
heres my code behind:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace AppName
{
public partial class HomePage : TabbedPage
{
public HomePage()
{
InitializeComponent();
}
}
}
I've searched google for the past 2 days so I thought it was time to ask!
Upvotes: 10
Views: 12340
Reputation: 596
For me, what I did was this:
(this.Parent as TabbedPage).CurrentPage = (this.Parent as TabbedPage).Children[2];
because in my tabbed page, I added my pages like this
this.Children.Add(new Landing());
this.Children.Add(new Categories());
this.Children.Add(new Collections());
this.Children.Add(new Options());
The above code snippets, will lead me to the Collections Page.
Upvotes: 3
Reputation: 161
public HomePage()
{
InitializeComponent();
CurrentPage = Children[2];
}
Upvotes: 16
Reputation: 5768
I think you have to set "CurrentPage" property.
In code is something like
TabbedPage tp = new TabbedPage();
tp.Children.Add(new PageFriends());
tp.Children.Add(new PageSnap());
tp.Children.Add(new PageNotes());
tp.CurrentPage = tp.Children[1];
Upvotes: 8
Reputation: 74094
You can access the enumerator of the TabbedPage
's children and advance its position two times to get your "second tab". Assign that page as your CurrentPage
:
public HomePage()
{
InitializeComponent();
var pages = Children.GetEnumerator();
pages.MoveNext(); // First page
pages.MoveNext(); // Second page
CurrentPage = pages.Current;
}
Upvotes: 15