How to load Tableview Dynamically

Asked

Viewed 172 times

2

I’m having trouble creating a menu dynamically by loading directly from a list. In my project this is the following way

<?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 fill the tableview dynamically coming directly from a list Category tried with for and foreach more unsuccessfully someone could give me a help?

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 website):

        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:"
                    }
                }
            }
        }
    };

Browser other questions tagged

You are not signed in. Login or sign up in order to post.