Search code examples
c#xamarinxamarin.formstabstoolkit

How to set first tab after loading page?


I`m using toolkit to make tabs on my page. I want to set special tab (in this context it is third tab) as showing tab after loading my tabPage. How can i do it? Thanks

    <xct:TabView IsTabTransitionEnabled="False" IsSwipeEnabled="False" x:Name="TabView" Style="{StaticResource CustomTabStyle}">              
                
               <xct:TabView.TabStripBackgroundView >                        
                        <BoxView BackgroundColor="White" HeightRequest="0" WidthRequest="30" CornerRadius="0,0,0,0" />                       
                </xct:TabView.TabStripBackgroundView>         


                <xct:TabViewItem 
                    Text="text1"
                    Icon="Logo.png"
                    x:Name="Tab1"        
                    ControlTemplate="{StaticResource TabItemTemplate}">
                    <view:Page1/>
                </xct:TabViewItem>

                <xct:TabViewItem
                    x:Name="Tab2"
                    Text="text2"                     
                    ControlTemplate="{StaticResource FabTabItemTemplate}"                    
                    <view:Page2 />
                </xct:TabViewItem>

                <xct:TabViewItem 
                    x:Name="Tab3"
                    Text="text3"                                       
                    ControlTemplate="{StaticResource TabItemTemplate}"             >
                    <view:Page3/>
                </xct:TabViewItem>

                </xct:TabView>   

Solution

  • You could just set SelectedIndex in your code behind like:

     public YourPage()
        {
            InitializeComponent();
            TabView.SelectedIndex = 2;  //TabView is the name you define in your xaml x:Name = "TabView"
        }