Beispiel #1
0
        // *** Private Methods ***

        private async Task <LoadMoreItemsResult> LoadMoreItemsAsyncInternal(int count)
        {
            IsLoading = true;

            // If we currently do not know the number of items then fetch this

            if (sourceCount == null)
            {
                sourceCount = await dataListSource.GetCountAsync();
            }

            // Set a minimum paging size if requested

            count = Math.Max(count, MinimumPagingSize);

            // Limit the number of items to fetch to the number of remaining items

            count = Math.Min(count, sourceCount.Value - currentCount);

            // Get all the items and wait until they are all fetched

            Task <T>[] fetchItemTasks = new Task <T> [count];
            int        startIndex     = currentCount;

            for (int i = 0; i < count; i++)
            {
                fetchItemTasks[i] = dataListSource.GetItemAsync(startIndex + i);
            }

            await Task.WhenAll(fetchItemTasks);

            // Increment the current count

            currentCount += count;

            // Set properties and raise property changed for HasMoreItems if this is not false

            IsLoading = false;

            if (currentCount == sourceCount)
            {
                OnPropertyChanged("HasMoreItems");
            }

            // Raise collection changed events

            OnItemsAdded(startIndex, count);

            // Return the number of items added

            return(new LoadMoreItemsResult()
            {
                Count = (uint)count
            });
        }
Beispiel #2
0
        // *** Overridden Base Methods ***

        protected override Task <int> GetCountAsync()
        {
            return(dataListSource.GetCountAsync());
        }