【问题标题】:Winrt implementation of ISupportIncrementalLoadingISupportIncrementalLoading 的 Winrt 实现
【发布时间】:2014-10-03 23:33:22
【问题描述】:

在我看来,我有一个 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

【问题讨论】:

    标签: c# windows-runtime scroll-paging


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多