コード例 #1
0
        protected async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            try
            {
                OnLoadMoreStarted?.Invoke(count);

                // 我们忽略了CancellationToken,因为我们暂时不需要取消,需要的可以加上
                var result = await _dataFetchDelegate(count);

                var items = result;

                if (items != null)
                {
                    foreach (var item in items)
                    {
                        Add(item);
                    }
                }

                // 加载完成事件
                OnLoadMoreCompleted?.Invoke(items?.Count ?? 0);

                return(new LoadMoreItemsResult {
                    Count = items == null ? 0 : (uint)items.Count
                });
            }
            finally
            {
                Busy = false;
            }
        }
コード例 #2
0
        protected async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            if (!HasMoreItems)
            {
                return new LoadMoreItemsResult {
                           Count = 0
                }
            }
            ;

            if (_dataFetchDelegate == null)
            {
                throw new NotImplementedException("IncrementalCollection's delegate is null");
            }

            try {
                OnLoadMoreStarted?.Invoke((int)count);

                //忽略了CancellationToken
                var result = await this._dataFetchDelegate(count);

                var items = result.Item1;
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        this.Add(item);
                    }
                }

                // 是否还有更多
                this.HasMoreItems = result.Item2;

                // 加载完成事件
                OnLoadMoreCompleted?.Invoke(items == null ? 0 : items.Count);

                return(new LoadMoreItemsResult {
                    Count = items == null ? 0 : (uint)items.Count
                });
            }
            finally {
                _busy = false;
            }
        }
    }
コード例 #3
0
        protected async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            var dispatcherQueue = Windows.System.DispatcherQueue.GetForCurrentThread();

            try
            {
                OnLoadMoreStarted?.Invoke(count);

                // 我们忽略了CancellationToken,因为我们暂时不需要取消,需要的可以加上
                var result = await _dataFetchDelegate(count);

                var items = result.Item1;

                if (items != null)
                {
                    await dispatcherQueue.EnqueueAsync(() =>
                    {
                        foreach (var item in items)
                        {
                            Add(item);
                        }
                    });
                }

                // 是否还有更多
                HasMoreItems = result.Item2;

                // 加载完成事件
                OnLoadMoreCompleted?.Invoke(items == null ? 0 : items.Count);

                return(new LoadMoreItemsResult {
                    Count = items == null ? 0 : (uint)items.Count
                });
            }
            finally
            {
                await dispatcherQueue.EnqueueAsync(() =>
                {
                    IsBusy = false;
                });
            }
        }
コード例 #4
0
        private async Task <LoadMoreItemsResult> LoadMoreItemsInternal(CancellationToken c, uint count)
        {
            try
            {
                // 加载开始事件
                OnLoadMoreStarted?.Invoke(this, count);

                var items = await LoadMoreItemsAsync(c, count);

                AddRange(items);

                // 加载完成事件
                OnLoadMoreCompleted?.Invoke(this, (uint)(items?.Count() ?? 0));

                return(new LoadMoreItemsResult {
                    Count = (uint)(items?.Count() ?? 0)
                });
            }
            finally
            {
                _busy = false;
            }
        }