ISupportIncrementalLoading最后两项在UI中显示不正确

时间:2017-02-21 12:03:46

标签: c# xaml listview

我在显示从服务器提取的最后两项时遇到问题。

我有下一个代码:

public class NotificationsToShow : ObservableCollection<Notification>, ISupportIncrementalLoading
        {
            public bool lastItem = false;

            public bool HasMoreItems
            {
                get
                {
                    return !lastItem;
                }
            }

            public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
            {
                CoreDispatcher coreDispatcher = Window.Current.Dispatcher;

                return Task.Run<LoadMoreItemsResult>(async () =>
                {
                    await coreDispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () =>
                    {
                        NavigationManager.Instance.IsApplicationBusy = true;
                    });

                    // HERE I REQUEST DATA FROM MY SERVER
                    List<Notification> items = await ServiceManager.Instance.GetNotificationsAsync(this.Count, 20);
                    if (items == null || items.Count == 0 || items.Count < 19)
                    {
                        // IF RETURNED is NULL or COUNT is ZERO or Count is smaller than requested amout then those were the last items. Set the flag
                        lastItem = true;
                    }

                    await coreDispatcher.RunAsync(CoreDispatcherPriority.Normal,
                        () =>
                        {
                            foreach (Notification item in items)
                            {
                                this.Add(item);
                            }

                            NavigationManager.Instance.IsApplicationBusy = false;
                        });

                    return new LoadMoreItemsResult() { Count = (uint)this.Count };

                }).AsAsyncOperation<LoadMoreItemsResult>();
            }
        }

我在UI上有下一个输出:

项目1 第2项 第3项 ... 项目59 第2项&lt; ===为什么? 第3项&lt; ===为什么?

在调试器中,我在这里看到我的数组并且它是正确的:

项目1 第2项 第3项 ... 项目59 项目60 第61项

我的错误在哪里?

在较小的屏幕上,我有这个问题再现50%的项目。

0 个答案:

没有答案