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!
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With