How do I use data from IResultSet on a UWP ListView?


#1

Hello,

I am learning Couchbase.Lite and trying to get data from a query result and put it on a UWP ListView.

A ListView (defined in xaml) may use a ItemsSource to populate it’s list.

<ListView ItemsSource="{Binding RecordingsList}"
             ...
	<TextBlock Text="{Binding ArtistName}" FontWeight="Bold"/>
	<TextBlock Text="{Binding CompositionName}"/>
             ...
</ListView>

ItemsSource receives a parameter (RecordingsList, in this examples) that is a list of some class objects. This class must have properties (ArtistName, CompositionName) that will be used to fill the columns of each row of the ListView.

public class Recording
{
    public string ArtistName { get; set; }
    public string CompositionName { get; set; }
}

My question is how do I get an IResultSet obtained from a query and create a list of simple objects as needed by ListView ItemssSource ?

Thank you,
Márcio


#2

You will need to go through an intermediate list which serializes each entry into the type of your choice (so basically iterating over each result and creating your Recording object and putting it into a separate collection).