コード例 #1
0
        public void DeferRefreshTest()
        {
            // verify that we do not need a refresh
            Assert.IsFalse(CollectionView.NeedsRefresh);

            // also verify that we don't have grouping
            Assert.IsNull(CollectionView.Groups);

            // once we set the DeferRefresh, sorts, groups, filters, and paging
            // should not be applied until the refresh is committed.
            using (CollectionView.DeferRefresh())
            {
                // we still don't need a refresh until we update states
                Assert.IsFalse(CollectionView.NeedsRefresh);

                // apply sorts, groups, filters, paging
                CollectionView.SortDescriptions.Add(new SortDescription("IntProperty", ListSortDirection.Descending));
                CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("IntProperty"));
                CollectionView.Filter   = this.FilterNegativeNumbers;
                CollectionView.PageSize = 10;
                CollectionView.MoveToPage(2);

                // now that we have deferred, we need a refresh
                Assert.IsTrue(CollectionView.NeedsRefresh);

                // verify that we haven't set up the groups yet
                Assert.IsNull(CollectionView.Groups);
            }

            // now verify that the CollectionView is updated
            Assert.AreEqual(10, CollectionView.PageSize);
            Assert.AreEqual(2, CollectionView.PageIndex);
            Assert.IsNotNull(CollectionView.Groups);
        }
コード例 #2
0
        private static IDisposable DeferResortHelper(
            IEnumerable itemsSourceCollection,
            CollectionView collectionView,
            SortDescriptionCollection sortDescriptions)
        {
            IDisposable resortDisposable = null;
            DataGridSortDescriptionCollection dataGridSortDescriptions = sortDescriptions as DataGridSortDescriptionCollection;

            if (dataGridSortDescriptions != null)
            {
                // We are in a detail
                resortDisposable = dataGridSortDescriptions.DeferResort();
            }
            else
            {
                Debug.Assert(collectionView != null, "We must have a CollectionView when we are not processing a Detail");

                DataGridCollectionViewBase dataGridCollectionView = itemsSourceCollection as DataGridCollectionViewBase;

                if (dataGridCollectionView != null)
                {
                    resortDisposable = dataGridCollectionView.DataGridSortDescriptions.DeferResort();
                }
                else
                {
                    resortDisposable = collectionView.DeferRefresh();
                }
            }
            Debug.Assert(resortDisposable != null);

            return(resortDisposable);
        }
コード例 #3
0
        public override void RefreshView()
        {
            if (IgnoreViewConfigChanges)
            {
                return;
            }

            Logger.Debug("Updating collection view settings.");
            using (CollectionView.DeferRefresh())
            {
                CollectionView.SortDescriptions.Clear();
                SetViewDescriptions();
            }
        }
コード例 #4
0
        protected IDisposable DeferResortHelper(
            IEnumerable itemsSourceCollection,
            CollectionView collectionView)
        {
            var dataGridCollectionView = itemsSourceCollection as DataGridCollectionViewBase;

            if (dataGridCollectionView != null)
            {
                return(dataGridCollectionView.DataGridSortDescriptions.DeferResort());
            }

            ColumnSortCommand.ThrowIfNull(collectionView, "collectionView");

            return(collectionView.DeferRefresh());
        }
コード例 #5
0
 private void ViewSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if ((new string[]
     {
         nameof(FullscreenViewSettings.SortingOrder),
         nameof(FullscreenViewSettings.SortingOrderDirection)
     }).Contains(e.PropertyName))
     {
         Logger.Debug("Updating collection view settings.");
         using (CollectionView.DeferRefresh())
         {
             CollectionView.SortDescriptions.Clear();
             SetViewDescriptions();
         }
     }
 }
コード例 #6
0
 public FullscreenCollectionView(
     IGameDatabase database,
     PlayniteSettings settings,
     ExtensionFactory extensions) : base(database, extensions, settings.Fullscreen.FilterSettings)
 {
     this.settings = settings;
     Database.Games.ItemCollectionChanged += Database_GamesCollectionChanged;
     Database.Games.ItemUpdated           += Database_GameUpdated;
     viewSettings = settings.Fullscreen.ViewSettings;
     viewSettings.PropertyChanged += ViewSettings_PropertyChanged;
     using (CollectionView.DeferRefresh())
     {
         SetViewDescriptions();
         Items.AddRange(Database.Games.Select(x => new GamesCollectionViewEntry(x, GetLibraryPlugin(x), settings)));
     };
 }
コード例 #7
0
        public void RemoveAndInsertSortDescriptionsTest()
        {
            // add groups and sorts
            using (CollectionView.DeferRefresh())
            {
                CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("StringProperty"));
                CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("IntProperty"));
                CollectionView.SortDescriptions.Add(new SortDescription("StringProperty", ListSortDirection.Ascending));
                CollectionView.SortDescriptions.Add(new SortDescription("IntProperty", ListSortDirection.Ascending));
            }

            // verify that we also get the correct number of groups
            Assert.AreEqual(2, CollectionView.Groups.Count);

            // change the direction of the first sort
            CollectionView.SortDescriptions.RemoveAt(0);
            CollectionView.SortDescriptions.Add(new SortDescription("StringProperty", ListSortDirection.Descending));

            // also verify that we still get the correct number of groups
            Assert.AreEqual(2, CollectionView.Groups.Count);
        }
コード例 #8
0
        private void SortingBoxChamps_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            CollectionView cv = (CollectionView)CollectionViewSource.GetDefaultView(ChampionsListBox.ItemsSource);

            if (cv == null)
            {
                return;
            }

            using (cv.DeferRefresh())
            {
                int i = SortingBoxChamps.SelectedIndex;
                switch (i)
                {
                case 0:
                    cv.SortDescriptions.Clear();
                    cv.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                    break;

                case 1:
                    cv.SortDescriptions.Clear();
                    cv.SortDescriptions.Add(new SortDescription("PurchaseDate", ListSortDirection.Ascending));
                    break;

                case 2:
                    if (mChampsWithSkins)
                    {
                        cv.SortDescriptions.Clear();
                        cv.SortDescriptions.Add(new SortDescription("HasSkin", ListSortDirection.Descending));
                        cv.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                    }
                    break;

                default:
                    break;
                }
            }
        }
コード例 #9
0
ファイル: ItemCollection.cs プロジェクト: sjyanxin/WPFSource
        // Change the collection view in use, unhook/hook event handlers 
        void SetCollectionView(CollectionView view)
        {
            if (_collectionView == view)
                return; 

            if (_collectionView != null) 
            { 
                // Unhook events first, to avoid unnecessary refresh while it is still the active view.
                if (!_isInitializing) 
                    UnhookCollectionView(_collectionView);

                if (IsRefreshDeferred)  // we've been deferring refresh on the _collectionView
                { 
                    // end defer refresh on the _collectionView that we're letting go
                    _deferInnerRefresh.Dispose(); 
                    _deferInnerRefresh = null; 
                }
            } 

            bool raiseReset = false;
            _collectionView = view;
            InvalidateEnumerableWrapper(); 

            if (_collectionView != null) 
            { 
                _deferInnerRefresh = _collectionView.DeferRefresh();
 
                ApplySortFilterAndGroup();

                // delay event hook-up when initializing.  see BeginInit() and EndInit().
                if (!_isInitializing) 
                    HookCollectionView(_collectionView);
 
                if (!IsRefreshDeferred) 
                {
                    // make sure we get at least one refresh 
                    raiseReset = !_collectionView.NeedsRefresh;

                    _deferInnerRefresh.Dispose();    // This fires refresh event that should reach ItemsControl listeners
                    _deferInnerRefresh = null; 
                }
                // when refresh is deferred, we hold on to the inner DeferRefresh until EndDefer() 
            } 
            else    // ItemsSource binding returned null
            { 
                if (!IsRefreshDeferred)
                {
                    raiseReset = true;
                } 
            }
 
            if (raiseReset) 
            {
                // notify listeners that the view is changed 
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }