Forum Xamarin.Forms

How to scuffle position of two Tabbar Shell Items programetically in run time using code behind c#.

REJAHREJAH Member ✭✭✭

How to scuffle position of two Tabbar Shell Items programetically in run time using code behind c# .

Tagged:

Answers

  • REJAHREJAH Member ✭✭✭

    Suffle position above two tabar items of shell.

  • ColeXColeX Member, Xamarin Team Xamurai

    We could swap the Title ,Icon , Route of that two tabs to simulate the position exchange .

    set X:Name on the two tab

        <Tab Title="111" x:Name="tab1">
            <ShellContent Route="cats"
                          Style="{StaticResource DomesticShell}"
                          Title="Cats"
                          Icon="cat.png"
                          ContentTemplate="{DataTemplate views:CatsPage}" />
        </Tab>
        <Tab Title="222" Route="Tab2" x:Name="tab2">
            <ShellContent 
                          Style="{StaticResource DomesticShell}"
                          Title="Cats"
                          Icon="cat.png"
                          ContentTemplate="{DataTemplate views:CatsPage}" />
        </Tab>
    

    swap the properties code behind.

            string title = tab2.Title;
            string route = tab2.Route;
            var icon = tab2.Icon;
    
            tab2.Title = tab1.Title;
            tab2.Icon = tab1.Icon;
            tab2.Route = tab1.Route;
    
            tab1.Title = title;
            tab1.Route = route;
            tab1.Icon = icon;
    

    Test on my side , it works fine .

  • REJAHREJAH Member ✭✭✭

    Working fine to scuffle tabbar icon, Also want to scuffle ShellContent inside the Tabbar.

  • REJAHREJAH Member ✭✭✭

    @ColeX I am unable to scuffle ShellContent inside the tabbar proggrametically in runtime

  • REJAHREJAH Member ✭✭✭

    I want scuffle two tab by code behind programetically

  • ColeXColeX Member, Xamarin Team Xamurai

    I found another way .

    You could define the ShellSection according to the tab in xaml , and exchange them in code .

    var item1 = new ShellSection
            {
                Title = "111",
                Items = {
                    new ShellContent
                    {
                        Title = "Dogs",
                        Icon = "dog.png",
                        ContentTemplate = new DataTemplate(typeof(DogsPage))
                    },
                    new ShellContent
                    {
                         Title = "Cats",
                         Icon = "cat.png",
                         ContentTemplate = new DataTemplate(typeof(CatsPage))
                    }
                }
            };
    
    
            var item2 = new ShellSection
            {
                Title = "222",
                Items = {
                    new ShellContent
                    {
                        Title = "Bears",
                        Icon = "bear.png",
                        ContentTemplate = new DataTemplate(typeof(BearsPage))
                    },
                    new ShellContent
                    {
                         Title = "Monkeys",
                         Icon = "monkey.png",
                         ContentTemplate = new DataTemplate(typeof(MonkeysPage))
                    }
                }
            };
    
    
            tabbar.Items[0] = item2;
            tabbar.Items[1] = item1;
    
Sign In or Register to comment.