How to Load TableView Dynamically

2

Hello, I'm having trouble creating a menu dynamically by loading directly from a list. In my project this is as follows

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.Master"
             Title="Master">
  <ContentPage.Content>
    <TableView x:Name="tbMenu">

    </TableView>   

  </ContentPage.Content>
</ContentPage>
 tbMenu.Root = new TableRoot
            {
                new TableSection("Menu")
                    {
                        new TextCell
                        {
                            Text = "DESTAQUE",
                            Command = navigateCommad,
                            CommandParameter = typeof(Default)

                        },
                        new TextCell
                        {
                            Text = "ESPORTES",
                            Command = navigateCommad,
                            CommandParameter = typeof(Default)

                        },
                        new TextCell
                        {
                            Text="ENTRETENIMENTO",
                            Command = navigateCommad,
                            CommandParameter = typeof(Default)
                        }

                    }

             };

I would like to populate the tableview dynamically coming directly from a Category list I tried with for and foreach more unsuccessfully could anyone give me a help?

    
asked by anonymous 17.10.2016 / 18:00

1 answer

2

You need to set the TableView Intent.

tbMenu.Intent = TableIntent.Settings; //ou TableIntent.Form

A nice example (it's on the Xamarin docs site):

        MainPage = new ContentPage {
            Content = new TableView {
            Intent = TableIntent.Form,
            Root = new TableRoot ("Table Title") {
                new TableSection ("Section 1 Title") {
                    new TextCell {
                        Text = "TextCell Text",
                        Detail = "TextCell Detail"
                    },
                    new EntryCell {
                        Label = "EntryCell:",
                        Placeholder = "default keyboard",
                        Keyboard = Keyboard.Default
                    }
                },
                new TableSection ("Section 2 Title") {
                    new EntryCell {
                        Label = "Another EntryCell:",
                        Placeholder = "phone keyboard",
                        Keyboard = Keyboard.Telephone
                    },
                    new SwitchCell {
                        Text = "SwitchCell:"
                    }
                }
            }
        }
    };
    
13.03.2017 / 19:52