Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Accessing item data in ListView ItemTemplate

$
0
0

Hi all,
I'm setting the ItemSource of a listview and trying to create multiple Labels within the listview DataTemplate based on the children of a property of that particular item (the items are gigs, and they have a list of band members and im trying to list the band members).

I'm not sure how to get the properties of the current item that's having it's template created, can someone help?

            ListView listView = new ListView {
            ItemsSource = viewModel.gigs,
                ItemTemplate = new DataTemplate (() => {

                    var grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star)});

                    for(int x = 0;x<=viewModel.bandMembers.Count;x++) {
                        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)});
                    }

                    var venueName = new Label { Text = "Top Left" };
                    venueName.SetBinding (Label.TextProperty, "Venue");
                    grid.Children.Add(venueName, 0, 0);

                    for(int x = 0;x<THISITEM.bandMembers.Count;x++) {
                        grid.Children.Add(new Label() {Text="Test"},x,0);
                    }

        return new ViewCell { View = grid };

            });

            // Build the page.
            this.Content = new StackLayout {
                Children = {
                    header,
                    listView
                }
            };

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>