Winu实现ISupportIncrementalLoading

时间:2014-08-14 15:00:19

标签: c# windows-runtime scroll-paging

在我看来,我有一个GridView。由于项目数量非常多,我试图将ISupportIncrementalLoading实现为新的ItemsSource。

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>();
    }
}

在导航功能中,我创建了一个新实例。

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

我现在的问题是调用LoadMoreItemsAsync很多次,以便在滚动后显示孔列表而不是预期。

我需要更改它只加载前50个项目以及滚动后需要的其他项目吗?

我试图像这里一样实现它: http://blogs.msdn.com/b/devosaure/archive/2012/10/15/isupportincrementalloading-loading-a-subsets-of-data.aspx

1 个答案:

答案 0 :(得分:0)

GridView可能会尝试利用无限空间,而不是将其大小限制为可见屏幕的大小。这将导致它继续查询以加载项目以填充可用空间,即使这些项目不可见。阅读此页面以获取更多相关信息,特别是它提到ScrollViewer的地方:http://msdn.microsoft.com/en-us/library/windows/apps/hh994637.aspx

相关问题