Erstelle eine ListView mit LoadMoreItemsAsync am Ende von scroll

Ich habe einListView in meiner Windows Phone 8.1-Anwendung und ich kann ungefähr 1000 oder mehr Ergebnisse erzielen, daher muss ich jedes Mal, wenn der Bildlauf den unteren Rand erreicht, eine Funktion zum Laden von mehr oder eine andere logische und natürliche Methode zum Auslösen des Hinzufügens von mehr Elementen zum implementieren Aufführen
Ich fand, dass dasListView hat Unterstützung für einISupportIncrementalLoading und fand diese Implementierung:https: //marcominerva.wordpress.com/2013/05/22/implementing-the-isupportincrementalloading-interface-in-a-window-store-app Dies war die bessere Lösung, die ich gefunden habe, da sie keinen Typ angibt, d. H., Sie ist generisch.

Mein Problem bei dieser Lösung ist, dass beim Laden der ListView dasLoadMoreItemsAsync wird so oft ausgeführt, bis alle Ergebnisse vorliegen, sodass das Laden von mehr nicht vom Benutzer ausgelöst wird. Ich bin mir nicht sicher, was die @ machLoadMoreItemsAsync Trigger, aber etwas stimmt nicht, da davon ausgegangen wird, dass es passiert, wenn ich die Seite öffne und alle Elemente an Ort und Stelle lade, ohne dass ich etwas tue oder scrolle. Hier ist die Implementierung:
IncrementalLoadingCollection.cs

public interface IIncrementalSource<T> {
    Task<IEnumerable<T>> GetPagedItems(int pageIndex, int pageSize);
    void SetType(int type);
}

public class IncrementalLoadingCollection<T, I> : ObservableCollection<I>, ISupportIncrementalLoading where T : IIncrementalSource<I>, new() {
    private T source;
    private int itemsPerPage;
    private bool hasMoreItems;
    private int currentPage;

    public IncrementalLoadingCollection(int type, int itemsPerPage = 10) {
        this.source = new T();
        this.source.SetType(type);
        this.itemsPerPage = itemsPerPage;
        this.hasMoreItems = true;
    }

    public bool HasMoreItems {
        get { return hasMoreItems; }
    }

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

        return Task.Run<LoadMoreItemsResult>(
            async () => {
                uint resultCount = 0;
                var result = await source.GetPagedItems(currentPage++, itemsPerPage);

                if(result == null || result.Count() == 0) {
                    hasMoreItems = false;
                }
                else {
                    resultCount = (uint)result.Count();

                    await dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        () => {
                            foreach(I item in result)
                                this.Add(item);
                        });
                }

                return new LoadMoreItemsResult() { Count = resultCount };

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

Hier ist diePersonModelSource.cs

public class DatabaseNotificationModelSource : IIncrementalSource<DatabaseNotificationModel> {
    private ObservableCollection<DatabaseNotificationModel> notifications;
    private int _type = "";

    public DatabaseNotificationModelSource() {
        //
    }

    public void SetType(int type) {
        _type = type;
    }

    public async Task<IEnumerable<DatabaseNotificationModel>> GetPagedItems(int pageIndex, int pageSize) {
        if(notifications == null) {
            notifications = new ObservableCollection<DatabaseNotificationModel>();
            notifications = await DatabaseService.GetNotifications(_type);
        }

        return await Task.Run<IEnumerable<DatabaseNotificationModel>>(() => {
            var result = (from p in notifications select p).Skip(pageIndex * pageSize).Take(pageSize);
                return result;
            });
    }
}

Ich habe es ein wenig geändert, da der Aufruf meiner Datenbank asynchron ist und ich nur so sicherstellen konnte, dass ich auf die Abfrage warten konnte, bevor ich die Sammlung füllte.

nd in meinemDatabaseNotificationViewModel.cs

IncrementalNotificationsList = new IncrementalLoadingCollection<DatabaseNotificationModelSource, DatabaseNotificationModel>(type);


Alles funktioniert einwandfrei, abgesehen von dem nicht so normalen "Mehr laden". Was ist in meinem Code falsch?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage