public void SetPage(Page page) { if (!page.Loaded) { provider.LoadPage(page, this.Invalidate); } //TODO: compare loaded pages and only remove those which are different while (loadedPages.Count > 0) { loadedPages.PopLeft()?.Dispose(); } loadedPages.PushRight(page); //Add previous pages Page previousPage = page; for (int i = 0; i < buffer; i++) { previousPage = provider.GetPreviousPage(previousPage, this.Invalidate, RefetchPages); loadedPages.PushLeft(previousPage); } //Add next pages Page nextPage = page; for (int i = 0; i < buffer; i++) { nextPage = provider.GetNextPage(nextPage, this.Invalidate, RefetchPages); loadedPages.PushRight(nextPage); } scrollOffset = 0; this.Invalidate(); }