Home > Enterprise >  I cannot seem to change the order of Xamarin.CommunityToolkit TabView tabs. Is there a way to do thi
I cannot seem to change the order of Xamarin.CommunityToolkit TabView tabs. Is there a way to do thi

Time:03-28

To begin, I'm a beginner at C# and Xamarin. I have an app with Xamarin Forms and am using the Xamarin Community Toolkit "TabView" to create a Snapchat-style application. I'm trying to make the app open on the second tab out of the three I have in XAML so it will be on the "middle" tab, but it keeps opening the application on the first (left-most) tab. Is there any sort of property to set the order of which opens initially?

I attempted to assign a value to each tab, but my efforts simply do not work. I also tried the TabIndex property, but I don't believe that correlates to the Community Toolkit.

    <!--Overall Tabs-->
<tk:TabView TabStripPlacement="Bottom" IsSwipeEnabled="False" TabStripBackgroundColor="#DD000000">
    <!--Left Tab-->
    <tk:TabViewItem Text="Data"> ... </tk:TabViewItem>
    <!--Middle Tab-->
    <tk:TabViewItem Text="Home"> ... </tk:TabViewItem>
    <!--Right Tab-->
    <tk:TabViewItem Text="Capture"> ... </tk:TabViewItem>
</tk:TabView>

Thanks all

CodePudding user response:

you need to set it in the code, after the tabs have loaded

first, give your tabs a name

<tk:TabView x:Name="myTabs" TabStripPlacement="Bottom" IsSwipeEnabled="False" TabStripBackgroundColor="#DD000000">

then in the code behind of the page

protected override void OnAppearing()
{
    base.OnAppearing();
    
    myTabs.SelectedIndex = 2;
}    
  • Related