Reputation: 103
in the UWP Toolkit Sample, in the Incremental Loading Collection scenario a List of type Person is created with 200 items and when demonstrating the helper it seems like when more items need to be read, then additional items are fetched from the existing list:
public async Task<IEnumerable<Person>> GetPagedItemsAsync(int pageIndex, int pageSize)
{
// Gets items from the collection according to pageIndex and pageSize parameters.
var result = (from p in _people
select p).Skip(pageIndex * pageSize).Take(pageSize);
// Simulates a longer request...
await Task.Delay(1000);
return result;
}
But what about if you wanted to call an API to fetch new items and add them to the list? What I would like to do and get suggestion on how are:
I have a feeling this is pretty easy to do but I can’t figure out from the sample how to do steps 2 and 3.
Any suggestions would be great!!
Thanks, Rick
Upvotes: 0
Views: 512
Reputation: 12465
You would need to change the GetPagesItemsAsync
method to call your API and return the items
public async Task<IEnumerable<Person>> GetPagedItemsAsync(int pageIndex, int pageSize)
{
// Call into your API classes to return a new collection
var people = await PeopleClient.GetPeople(pageIndex);
return people;
}
In this example the PeopleClient would be a class that uses the HttpClient class to make a HTTP call to some resource and return the result as a Person object.
Upvotes: 2