如何使用 UWP 在列表视图中使用增量加载集合上下滚动?

How to scrolling up and down using Incremental Loading Collection in a list view using UWP?

IncrementalLoadingCollection 示例展示了如何在向下滚动时使用增量加载集合(无限滚动)创建应用程序。

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;

但我需要视图从列表的中间开始显示,如果滚动 向上 和向下滚动,项目应该像已经发生的那样逐渐加载 向下滚动。有谁知道如何使用 IncrementalLoadingCollection 执行此操作或可以提出解决方案?感激不尽

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.

我不得不说我们不能用 IncrementalLoadingCollection 实现上面的内容,因为它不会检测 listview end to top。你的需求可以参考我之前的.

并监听scrollViewer.VerticalOffset值,如果该值变为0,可以调用load more方法,然后将新项插入到集合的头部。请注意,加载列表视图时需要确保 VerticalOffset 值大于 0。这可以使列表视图可以向上滚动。