public ReadOnlySelectionCollection(IReadOnlyIdentityCollection <T> identityCollection)
        {
            allItems = new ObservableCollection <ISelectionItem <T> >();
            AllItems = new ListCollectionView(allItems);

            CheckedItems = new ListCollectionView(allItems)
            {
                Filter          = new Predicate <object>(IsCheckedFilter),
                IsLiveFiltering = true
            };
            CheckedItems.LiveFilteringProperties.Add("IsChecked");

            SelectedItems = new ListCollectionView(allItems)
            {
                Filter          = new Predicate <object>(IsSelectedFilter),
                IsLiveFiltering = true
            };
            SelectedItems.LiveFilteringProperties.Add("IsSelected");

            collection = identityCollection ?? throw new ArgumentNullException(nameof(identityCollection) + " can not be null");

            collection.CollectionChangeAdded   += OnCollectionChangeAdded;
            collection.CollectionChangeRemoved += OnCollectionChangeRemoved;
            collection.CollectionChangeCleared += OnCollectionChangeCleared;

            if (collection.Count > 0)
            {
                Add(collection);
            }
        }
        public IdentitySelectionListViewModel(IReadOnlyIdentityCollection <T> identityCollection)
        {
            collection = identityCollection ?? throw new ArgumentNullException(nameof(identityCollection) + " can not be null");
            collection.CollectionChangeAdded   += OnCollectionChangeAdded;
            collection.CollectionChangeRemoved += OnCollectionChangeRemoved;
            collection.CollectionChangeCleared += OnCollectionChangeCleared;

            viewModelDictionary = new Dictionary <IIdentifier, Tuple <T, TViewModel> >();
            allItems            = new ObservableCollection <IIdentitySelectionListItemViewModel <T> >();
            AllItems            = new ListCollectionView(allItems);

            CheckedItems = new ListCollectionView(allItems)
            {
                Filter          = new Predicate <object>(IsCheckedFilter),
                IsLiveFiltering = true
            };
            CheckedItems.LiveFilteringProperties.Add("IsChecked");

            SelectedItems = new ListCollectionView(allItems)
            {
                Filter          = new Predicate <object>(IsSelectedFilter),
                IsLiveFiltering = true
            };
            SelectedItems.LiveFilteringProperties.Add("IsSelected");

            commandGroupsList = CreateCommandGroups();
            CommandGroups     = new ReadOnlyCollection <CommandGroupViewModel>(commandGroupsList);

            CreateViewModels();
        }
        public override void Close()
        {
            collection.CollectionChangeAdded   -= OnCollectionChangeAdded;
            collection.CollectionChangeRemoved -= OnCollectionChangeRemoved;
            collection.CollectionChangeCleared -= OnCollectionChangeCleared;
            collection = null;

            allItems.Clear();
            allItems = null;
            viewModelDictionary.Clear();
            viewModelDictionary = null;

            base.Close();
        }