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