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

List inside ListView

$
0
0

Can someone suggest how I can create a list of objects that contains a list of object?

In xaml

LoadList.ItemsSource = ViewModel.Loads;
LoadList.ItemTemplate = new DataTemplate(typeof(SelectLoadCell));
LoadList.HasUnevenRows = true;

Inside the ViewModel.Loads

<StackLayout BackgroundColor="#cae5ee" Orientation="Horizontal">
            <StackLayout Orientation="Vertical">
                <Label x:Name="Year" Font="Small" Text="{Binding Description}"></Label>
                <ListView x:Name="SampleList" HasUnevenRows="true" BackgroundColor="#cae5ee" ItemsSource="{Binding MyList}" />
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <ViewCell.View>
                                    <Label x:Name="Info" Font="Small" TextColor="Green" Text="{Binding Place}"></Label>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
            </StackLayout>
</StackLayout>

Load.cs

public class Stop { 
    public string Location { get; set; }
    public string Place { get; set; }
}

    public Load ()
    {
        StopList.Add (new Stop { Location = "01", Place = "Bent" });
        StopList.Add (new Stop { Location = "02", Place = "fewfe" });
        StopList.Add (new Stop { Location = "02", Place = "12341212" });
    }

    public List<Stop> MyList {
        get { 
            return StopList; 
        }
    }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



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