public MultiViewModel() { var collection = new SynchronizedNotifiableCollection<IViewModel>(); var list = ServiceProvider.TryDecorate(collection); Should.BeOfType<INotifiableCollection<IViewModel>>(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection<IViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate<MultiViewModel, ViewModelClosedEventArgs, EventHandler<ICloseableViewModel, ViewModelClosedEventArgs>>(this, (model, o, arg3) => model.ItemsSource.Remove(arg3.ViewModel), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); DisposeViewModelOnRemove = true; }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection <IViewModel>(); var list = ServiceProvider.TryDecorate(collection); Should.BeOfType <INotifiableCollection <IViewModel> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <IViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate <MultiViewModel, ViewModelClosedEventArgs, EventHandler <ICloseableViewModel, ViewModelClosedEventArgs> >(this, (model, o, arg3) => model.ItemsSource.Remove(arg3.ViewModel), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); DisposeViewModelOnRemove = true; }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection <TViewModel>(); var list = ServiceProvider.TryDecorate(this, collection); Should.BeOfType <INotifiableCollection <TViewModel> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <TViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); var weakReference = ToolkitExtensions.GetWeakReference(this); _closeViewModelWeakHandler = (dispatcher, vm, arg3) => { var self = (MultiViewModel <TViewModel>)weakReference.Target; return(self?.CloseViewModel(dispatcher, vm, arg3) ?? Empty.FalseTask); }; DisposeViewModelOnRemove = ApplicationSettings.MultiViewModelDisposeViewModelOnRemove; CloseViewModelsOnClose = ApplicationSettings.MultiViewModelCloseViewModelsOnClose; }
public void SetOriginalItemsSource <TItemsSource>(TItemsSource originalItemsSource) where TItemsSource : IList <T>, INotifyCollectionChanged, IList { EnsureNotDisposed(); Should.NotBeNull(originalItemsSource, "originalItemsSource"); lock (_weakPropertyHandler) { INotifyCollectionChanging collectionChanging; if (_originalData != null) { collectionChanging = _originalData as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging -= RaiseCollectionChanging; } ((INotifyCollectionChanged)(_originalData)).CollectionChanged -= RaiseCollectionChanged; if (_originalData.Count != 0) { originalItemsSource.AddRange(_originalData); } } _filterableItemsSource = new FilterableNotifiableCollection <T>(originalItemsSource); collectionChanging = originalItemsSource as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging += RaiseCollectionChanging; } originalItemsSource.CollectionChanged += RaiseCollectionChanged; _originalData = originalItemsSource; var list = ServiceProvider.TryDecorate(FilterableItemsSource); Should.BeOfType <INotifiableCollection <T> >(list, "DecoratedItemsSource"); Should.BeOfType <INotifiableCollection>(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <T>)list; } UpdateFilter(); OnPropertyChanged("ItemsSource"); OnPropertyChanged("OriginalItemsSource"); }
public void SetOriginalItemsSource <TItemsSource>(TItemsSource originalItemsSource) where TItemsSource : IList <T>, INotifyCollectionChanged, IList { EnsureNotDisposed(); Should.NotBeNull(originalItemsSource, nameof(originalItemsSource)); INotifyCollectionChanging collectionChanging; if (_originalData != null) { collectionChanging = _originalData as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging -= RaiseCollectionChanging; } ((INotifyCollectionChanged)_originalData).CollectionChanged -= RaiseCollectionChanged; if (_originalData.Count != 0) { originalItemsSource.AddRange(_originalData, true); } } _filterableItemsSource = new FilterableNotifiableCollection <T>(originalItemsSource); collectionChanging = originalItemsSource as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging += RaiseCollectionChanging; } originalItemsSource.CollectionChanged += RaiseCollectionChanged; _originalData = originalItemsSource; var list = ToolkitServiceProvider.TryDecorate(this, FilterableItemsSource); Should.BeOfType <INotifiableCollection <T> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <T>)list; UpdateFilter(); OnPropertyChanged(nameof(ItemsSource)); OnPropertyChanged(nameof(OriginalItemsSource)); RaiseItemsSourceChanged(_itemsSource); }
public BindingListWrapper(INotifiableCollection <T> collection = null) : base(collection ?? new SynchronizedNotifiableCollection <T>()) { CollectionChanged += CollectionOnCollectionChanged; }
public static BindingListWrapper <T> ToBindingList <T>(this INotifiableCollection <T> collection) { Should.NotBeNull(collection, nameof(collection)); return(new BindingListWrapper <T>(collection)); }