【问题标题】:How to scrolling up and down using Incremental Loading Collection in a list view using UWP?如何使用 UWP 在列表视图中使用增量加载集合向上和向下滚动?
【发布时间】:2021-11-20 19:48:09
【问题描述】:

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 执行此操作或可以提出解决方案?感激不尽。

【问题讨论】:

    标签: c# windows visual-studio listview uwp


    【解决方案1】:

    但我需要从列表中间开始显示视图,如果上下滚动,项目应该像向下滚动时那样增量加载。

    我不得不说我们不能在上面用IncrementalLoadingCollection 实现,因为它不会检测到列表视图的端到端。您的要求可以参考我之前的reply

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

    【讨论】:

      猜你喜欢
      • 2020-04-22
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      相关资源
      最近更新 更多