private void InitCollectionViewGroup(DependencyCollectionView view, int count) { if (view.CollectionGroups?.Count != count) { view.CollectionGroups.Clear(); for (int i = 0; i < count; i++) { var g = new DependencyCollectionViewGroup(i, view); view.CollectionGroups.Add(g); } if ((view.CollectionGroups?.Count ?? 0) != 0) { foreach (var item in view) { this.TryAddItemToGroup(item); } } } }