C# iSupportIncrementLoading的Winrt实现

C# iSupportIncrementLoading的Winrt实现,c#,windows-runtime,scroll-paging,C#,Windows Runtime,Scroll Paging,在我看来,我有一个网格视图。由于项目的数量可能非常高,我正在尝试实现ISupportIncrementalLoading作为新项目资源 public class IncrementalCollection : ObservableCollection<Object>, ISupportIncrementalLoading { private int _addedItems = 0; private const int _PAGESIZE = 2

在我看来,我有一个网格视图。由于项目的数量可能非常高,我正在尝试实现ISupportIncrementalLoading作为新项目资源

public class IncrementalCollection : ObservableCollection<Object>, ISupportIncrementalLoading
    {
        private int _addedItems = 0;
        private const int _PAGESIZE = 20;

        private IList<BookingDTO> _bookings;

        public IncrementalCollection(Guid guid)
        {
            LoadBookings(guid);
    }

    private async Task LoadBookings(Guid guid)
    {
        var data = await IoC.Resolve<IMBAMService>().GetOrderedBookingsForAccountAsync(guid);
        _bookings = data.Data;
    }

    public bool HasMoreItems
    {
        get { return (this.Count < _bookings.Count); }
    }

    public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
    {
        var coreDispatcher = Window.Current.Dispatcher;

        return Task.Run<LoadMoreItemsResult>(async () =>
        {
            await coreDispatcher.RunAsync(CoreDispatcherPriority.High,
                () =>
                {
                    foreach (var item in _bookings.Skip(_addedItems).Take((int)count))
                    {
                        _addedItems++;
                        this.Add(item);
                    }
                });
            return new LoadMoreItemsResult() { Count = count };
        }).AsAsyncOperation<LoadMoreItemsResult>();
    }
}
现在我的问题是LoadMoreItemsAsync被调用了很多次,以至于在滚动后孔列表将显示出来,而不是像预期的那样

我需要改变什么,它只加载前50个项目,在滚动后需要时加载其余的项目

我试着在这里实现它:
可能GridView试图利用无限空间,而不是将其大小限制为可见屏幕的大小。这将导致它不断查询加载项以填充可用空间,即使这些项不可见。阅读本页了解更多信息,特别是其中提到ScrollViewer:

BookingList.ItemsSource = new IncrementalCollection(ViewModel.Account.Id);BookingList.ItemsSource = new IncrementalCollection(Guid);