コード例 #1
0
        internal override void ForceRefresh(bool sendResetNotification, bool initialLoad, bool setCurrentToFirstOnInitialLoad)
        {
            if (this.Refreshing)
            {
                throw new InvalidOperationException("An attempt was made to refresh the DataGridVirtualizingCollectionView while it is already in the process of refreshing.");
            }

            if (this.IsRefreshingDistinctValues)
            {
                throw new InvalidOperationException("An attempt was made to refresh the DataGridVirtualizingCollectionView while it is already in the process of refreshing distinct values.");
            }

            this.SetCurrentEditItem(null);
            int oldCurrentPosition = -1;

            if (!initialLoad)
            {
                this.SaveCurrentBeforeReset(out oldCurrentPosition);
            }

            using (this.DeferCurrencyEvent())
            {
                this.Refreshing = true;
                try
                {
                    lock (this.SyncRoot)
                    {
                        lock (this.DeferredOperationManager)
                        {
                            this.DeferredOperationManager.ClearDeferredOperations();

                            // We explicitly go through base so we do not end-up creating a RootGroup if there is none existing at the moment.
                            DataGridVirtualizingCollectionViewGroupBase rootGroup = base.RootGroup as DataGridVirtualizingCollectionViewGroupBase;
                            if (rootGroup != null)
                            {
                                DataGridPageManagerBase pageManager = rootGroup.GetVirtualPageManager();

                                // The pageManager can be null when no queryable source was set yet.
                                if (pageManager != null)
                                {
                                    // Disconnect the PageManager so that subsequent Items/Count interrogations are not processed.
                                    pageManager.Disconnect();

                                    // Restart all virtual lists.  The DataGridPageManagerBase will make a call to ForceRefresh once everything has been restarted if
                                    // commit operations had to be made.
                                    pageManager.Restart();
                                }
                            }

                            // Ensure to clear the DistinctValues cache when refreshing
                            // since the source could have changed
                            this.ResetDistinctValues();

                            base.RootGroup = this.CreateNewRootGroup();

                            // We set the current item to -1 to prevent the developper to get an invalid position.
                            // We will replace the current item to the correct one later.
                            this.SetCurrentItem(-1, null, false, false);
                        }
                    }
                }
                finally
                {
                    this.Refreshing = false;
                }

                if (initialLoad)
                {
                    this.Loaded = true;
                }
                else
                {
                    this.AdjustCurrencyAfterReset(oldCurrentPosition);
                }

                if (sendResetNotification)
                {
                    this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                }

                this.OnPropertyChanged(new PropertyChangedEventArgs("Groups"));
            }
        }