-1

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>   
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
votcod
  • 13
  • 2

2 Answers2

1

See https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/tabview

TabView has a SelectedIndex property which you can use to set the selected tab.

Mateus Henrique
  • 188
  • 2
  • 10
  • I tried to use it. I set SelectedIndex="2" and set TabIndex="2" for my needed tab. But i got exception "Index is out of range"... Can you show me code where it works? Thanks. – votcod Mar 16 '21 at 13:32
  • SelectedIndex and TabIndex have no correlation. TabIndex is a "Xamarin default property" (part of VisualElement) for when you have a keyboard on the device and want to TAB from element to element. SelectedIndex expects the index of the tab beginning at zero. When using it with your example it should show the third tab though and not throw an IndexOutOfRangeException. – Christoph Mett Feb 02 '22 at 17:39
0

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"
    }
Leo Zhu
  • 15,726
  • 1
  • 7
  • 23