private void InnerAdd(object view, string viewName, IRegionManager scopedRegionManager) { if (this.ItemMetadataCollection.FirstOrDefault(x => x.Item == view) != null) { throw new InvalidOperationException(Resources.RegionViewExistsException); } ItemMetadata itemMetadata = new ItemMetadata(view); if (!string.IsNullOrEmpty(viewName)) { if (this.ItemMetadataCollection.FirstOrDefault(x => x.Name == viewName) != null) { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, Resources.RegionViewNameExistsException, viewName)); } itemMetadata.Name = viewName; } DependencyObject dependencyObject = view as DependencyObject; if (dependencyObject != null) { Regions.RegionManager.SetRegionManager(dependencyObject, scopedRegionManager); } this.ItemMetadataCollection.Add(itemMetadata); }
public void CollectionChangedPassesWrappedItemInArgumentsWhenRemoving() { var originalCollection = new ObservableCollection<ItemMetadata>(); IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => true); IList newItemsPassed = null; viewsCollection.CollectionChanged += (s, e) => { newItemsPassed = e.NewItems; }; var filteredInObject = new ItemMetadata(new object()); originalCollection.Add(filteredInObject); Assert.IsNotNull(newItemsPassed); Assert.AreEqual(1, newItemsPassed.Count); Assert.AreSame(filteredInObject.Item, newItemsPassed[0]); }
public void RaisesCollectionChangedWithAddAndRemoveWhenFilteredCollectionChanges() { var originalCollection = new ObservableCollection<ItemMetadata>(); IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.IsActive); bool addedToCollection = false; bool removedFromCollection = false; viewsCollection.CollectionChanged += (s, e) => { if (e.Action == NotifyCollectionChangedAction.Add) { addedToCollection = true; } else if (e.Action == NotifyCollectionChangedAction.Remove) { removedFromCollection = true; } }; var filteredInObject = new ItemMetadata(new object()) { IsActive = true }; originalCollection.Add(filteredInObject); Assert.IsTrue(addedToCollection); Assert.IsFalse(removedFromCollection); originalCollection.Remove(filteredInObject); Assert.IsTrue(removedFromCollection); }
public void DoesNotRaiseCollectionChangedWhenAddingOrRemovingFilteredOutObject() { var originalCollection = new ObservableCollection<ItemMetadata>(); IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.IsActive); bool collectionChanged = false; viewsCollection.CollectionChanged += (s, e) => collectionChanged = true; var filteredOutObject = new ItemMetadata(new object()) { IsActive = false }; originalCollection.Add(filteredOutObject); originalCollection.Remove(filteredOutObject); Assert.IsFalse(collectionChanged); }