public PagedCollectionView(IEnumerable source, bool isDataSorted, bool isDataInGroupOrder) { NotifyCollectionChangedEventHandler handler = null; this._cachedPageIndex = -1; this._currentChangedMonitor = new SimpleMonitor(); this._flags = CollectionViewFlags.ShouldProcessCollectionChanged; this._pageIndex = -1; if (source == null) { throw new ArgumentNullException("source"); } this._sourceCollection = source; this.SetFlag(CollectionViewFlags.IsDataSorted, isDataSorted); this.SetFlag(CollectionViewFlags.IsDataInGroupOrder, isDataInGroupOrder); this._temporaryGroup = new CollectionViewGroupRoot(this, isDataInGroupOrder); this._group = new CollectionViewGroupRoot(this, false); this._group.GroupDescriptionChanged += new EventHandler(this.OnGroupDescriptionChanged); this._group.GroupDescriptions.add_CollectionChanged(new NotifyCollectionChangedEventHandler(this, (IntPtr)this.OnGroupByChanged)); this.CopySourceToInternalList(); this._trackingEnumerator = source.GetEnumerator(); if (this._internalList.Count > 0) { this.SetCurrent(this._internalList[0], 0, 1); } else { this.SetCurrent(null, -1, 0); } this.SetFlag(CollectionViewFlags.CachedIsEmpty, this.Count == 0); this._pollForChanges = !(source is INotifyCollectionChanged); if (!this._pollForChanges) { if (handler == null) { handler = new NotifyCollectionChangedEventHandler(this, (IntPtr)this.OnNotifyCollectionChanged); } (source as INotifyCollectionChanged).add_CollectionChanged(handler); } }
private void PrepareTemporaryGroups() { this._temporaryGroup = new CollectionViewGroupRoot(this, this.CheckFlag(CollectionViewFlags.IsDataInGroupOrder)); foreach (GroupDescription description in this._group.GroupDescriptions) { this._temporaryGroup.GroupDescriptions.Add(description); } this._temporaryGroup.Initialize(); this._isGrouping = false; if (this._temporaryGroup.GroupDescriptions.Count > 0) { int num = 0; int count = this._internalList.Count; while (num < count) { object objB = this._internalList[num]; if ((objB != null) && (!this.IsAddingNew || !object.Equals(this.CurrentAddItem, objB))) { this._temporaryGroup.AddToSubgroups(objB, true); } num++; } if (this.IsAddingNew) { this._temporaryGroup.InsertSpecialItem(this._temporaryGroup.Items.Count, this.CurrentAddItem, true); } } this._isGrouping = this._temporaryGroup.GroupBy != null; this.PrepareGroupingComparer(this._temporaryGroup); }
private void PrepareGroupingComparer(CollectionViewGroupRoot groupRoot) { if ((groupRoot == this._temporaryGroup) || (this.PageSize == 0)) { CollectionViewGroupInternal.ListComparer activeComparer = groupRoot.ActiveComparer as CollectionViewGroupInternal.ListComparer; if (activeComparer != null) { activeComparer.ResetList(this.InternalList); } else { groupRoot.ActiveComparer = new CollectionViewGroupInternal.ListComparer(this.InternalList); } } else if (groupRoot == this._group) { groupRoot.ActiveComparer = new CollectionViewGroupInternal.CollectionViewGroupComparer(this._temporaryGroup); } }