Reputation: 139
This example of IncrementalLoadingCollection shows how to created an app with Incremental Loading Collection (Infinite scrolling) when scrolling down.
XAML:
<ListView x:Name="PeopleListView">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Person">
<TextBlock Text="{x:Bind Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
C#:
public class Person
{
public string Name { get; set; }
}
public class PeopleSource : IIncrementalSource<Person>
{
private readonly List<Person> people;
public PeopleSource()
{
// Populate people
...
}
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);
}
}
var collection = new IncrementalLoadingCollection<PeopleSource, Person>();
PeopleListView.ItemsSource = collection;
But I need the view to starts showing from middle of the list, and if scrolling up and down, the items should be incrementally loaded like already happens when scrolling down. Does anyone know how to do this using IncrementalLoadingCollection or can suggest a solution? Grateful.
Upvotes: 0
Views: 404
Reputation: 32775
But I need the view to starts showing from middle of the list, and if scrolling up and down, the items should be incrementally loaded like already happens when scrolling down.
I have to say we can't implement above with IncrementalLoadingCollection
, because it will not detect listview end to top. For your requirement you could refer to my previous reply.
And listen scrollViewer.VerticalOffset
value, if the value turn into 0, you could call load more method, then insert new items into the head of collection. And please note you need make sure VerticalOffset value large than 0 when listview loaded. That could make listview can scroll up at fist.
Upvotes: 1