Asif Inn. Lab
Asif Inn. Lab

Reputation: 7

How to set specific tab when tabs opened

I am new to Xamarin. So the problem is when I open my tabs it opens the first one i.e "Schedule_FRI". But I want to open "Schedule_SAT" when I open the tab pages. Is this possible and how do I do that?

<?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:App4.Pages;assembly=App4"
            xmlns:i8ln="clr-namespace:App4;assembly=App4"
            x:Class="App4.Pages.Schedule" Title="{i8ln:Translate PageName_Schedule}">

  <local:Schedule_FRI Title="{i8ln:Translate FRI}"/>
  <local:Schedule_SAT Title="{i8ln:Translate SAT}"/>
  <local:Schedule_SUN Title="{i8ln:Translate SUN}"/>

  <local:Schedule_Lajna Title="{i8ln:Translate Schedule_Lajna}"/>


</TabbedPage>

Upvotes: 0

Views: 1174

Answers (2)

Ljupcho Hristov
Ljupcho Hristov

Reputation: 275

When you navigate to the page after creating the instance of the Tab page

for example:

            var page = new App4.Pages.Schedule();

You need to set current page (the tab that you want to be active).

[Hint Array indexes start from 0 ;) if you want second tab to be active put 1 in Children Array]

            page.CurrentPage = page.Children[{{INT TAB PAGE INDEX HERE}}];

and in the end set the Tabbed Page as MainPage

            Application.Current.MainPage = new MainPage(page);

Upvotes: 1

Ben Jackson
Ben Jackson

Reputation: 1138

I don't think you can set this in the XAML, but you can set this in code using the CurrentPage property, e.g. in a page load event handler. Add an x:Name attribute to your tab pages to allow them to be easily referenced in code, e.g. x:name="satSchedulePage", and then you'll be able to put this.CurrentPage = this.satSchedulePage; within the TabbedPage code.

Upvotes: 0

Related Questions