Forum Xamarin.Forms

FlyoutItem dynamically loaded

Erol2309Erol2309 Member ✭✭

Hello,
Is there any way to bind the items displayed in the shell FlyoutItem? In my app i want to enable to user too add devices after which these devices will be displayed in the Flyout.
Thank you

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Do you want to add the ShellContent using C# dynamically

     ShellSection shell_section = new ShellSection
            {
                Title = "home",
            };
    
            shell_section.Items.Add(new ShellContent() { Content = new ItemsPage() });
    
            ShellSection shell_section1 = new ShellSection
            {
                Title = "about",
    
    
            };
    
            shell_section1.Items.Add(new ShellContent() { Content = new AboutPage() });
    
            myshell.Items.Add(shell_section);
            myshell.Items.Add(shell_section1);
    

    myshell is the name of Shell.

  • Erol2309Erol2309 Member ✭✭
    LeonLu thank you for taking your time to answer, but i was wondering if it can be done via a binding? So that a VM property would populate the FlyoutItem.Items?
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    If you want to achieve binding like following binding.

     <FlyoutItem Route="animals"
                    Title="{Binding FlyoutItemTitle}"
                    FlyoutDisplayOptions="AsMultipleItems">
            <Tab Title="{Binding FlyoutItemTitle}"
                 Route="domestic"
                 Icon="paw.png">
                <ShellContent Route="cats"
                              Style="{StaticResource DomesticShell}"
                              Title="{Binding FlyoutItemTitle}"
                              Icon="cat.png"
                              ContentTemplate="{DataTemplate views:CatsPage}" />
                <ShellContent Route="dogs"
                              Style="{StaticResource DomesticShell}"
                              Title="Dogs"
                              Icon="dog.png"
                              ContentTemplate="{DataTemplate views:DogsPage}" />
            </Tab>
     </FlyoutItem>
    

    I change the Title of FlyoutItem to Title="{Binding FlyoutItemTitle}", FlyoutItemTitle is a property in the background code.

     public string FlyoutItemTitle { get; set; }
     FlyoutItemTitle = "test";
    

    If you want to achieve this type, it could be achieve it.

Sign In or Register to comment.