コード例 #1
0
        internal void FillEmptyPage(AsyncQueryInfo asyncQueryInfo, object[] fetchedItems)
        {
            // The VirtualList is disposed or part of a PagingManager that will be disposed (only disconnected when dispose is required)
            if (!this.PagingManager.IsConnected)
            {
                return;
            }

            Debug.Assert(!this.IsDisposed);
            Debug.Assert(!asyncQueryInfo.IsDisposed);

            // We do not want to move the page we are about to fill to the front since it does not count as a legitimate user-acess.  It will get moved to the front when one of its item is accessed.
            VirtualPage page = null;

            page = this.GetPageOrDefaultForItemIndex(asyncQueryInfo.StartIndex, true);

            // Although extremely rare, this situation could occur if we are calling RemovePageNode and the QueryData Dispatcher Operation
            // which has been asyncronously invoked in CreateNewPage is raising the QueryData event at the exact moment when we
            // try to abort the dispatcher operation.  This means that the customer will have queued an async request for data
            // for a page we no longer care about, and have already removed from the Table of Content and our LinkedList.
            // This should NOT occur if the user did not abort the request and called the AsyncQueryInfo EndQuery method since AsyncQueryInfo should
            // not have invoked the EndQueryAction if its ShouldAbort property was set to true.
            if (page == null)
            {
                return;
            }

            Debug.Assert(!page.IsFilled);
            Debug.Assert(this.GetPageStartingIndexForItemIndex(asyncQueryInfo.StartIndex) == asyncQueryInfo.StartIndex);

            Debug.Assert(fetchedItems.Length <= page.Count);

            if (fetchedItems.Length == page.Count)
            {
                object[] oldItems = page.ToItemArray();

                m_tableOfContent.RemovePage(page);

                page.EndQueryItems(asyncQueryInfo, fetchedItems);

                m_tableOfContent.AddPage(page);

                Debug.WriteLineIf(VirtualPageManager.DebugDataVirtualization, "Replaced TOC items/index for page: " + page.ToString());

                this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, fetchedItems, oldItems, asyncQueryInfo.StartIndex));
            }
            else
            {
                // The expected count was not met.  Maybe the user told us the source was bigger than it really is, or maybe there were delete operations made on the source since the last restart.
                // Let's refresh the CollectionView. This will restart the VirtualItemBook and raise the CollectionView's OnCollectionChanged Reset notification.
                this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }