Reputation: 51
Let's say, I have some model UserModel.cs
which looks like this:
class UserModel
{
string FirstName { get; set; }
int BirthYear { get; set; }
}
and I have some view DataViewer.cs
which looks like this:
class DataViewer
{
static void ShowData()
{
var users = new List<UserModel>()
{
new UserModel() { FirstName = "Thomas", BirthYear = 1995 },
new UserModel() { FirstName = "Arthur", BirthYear = 1991 },
new UserModel() { FirstName = "John", BirthYear = 2000 }
};
foreach (var user in users)
{
Console.WriteLine($"{user.FirstName} was born in {user.BirthYear}");
}
}
}
Upvotes: 0
Views: 1082
Reputation: 771
Just follow the given exemple on the documentation which you can find here. I can't help you more that the official documentation as it is very solid on CollectionView : a lot of exemple and how to make it working.
Anyway here is a starting point :
<CollectionView ItemsSource="{Binding Users}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding FirstName}" />
<Label Text="{Binding BirthYear}" />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Assuming you have a collection property called Users in your ViewModel.
Upvotes: 2