protected void AddDependencySource(string name, INotifyCollectionChanged source) { ArgumentValidation.NotNullOrEmpty <char>(name, "name"); ArgumentValidation.NotNull(source, "source"); _collectionSources.Value.Add(source, name); CollectionChangedEventManager.AddListener(source, this); }
/// <summary> /// Listens for change events on a list. /// </summary> /// <param name="list">The list to listen to.</param> protected void ListenForChangeEvents(IList list) { if (list is INotifyCollectionChanged) { CollectionChangedEventManager.AddListener(list as INotifyCollectionChanged, this); } }
/// <summary> /// Effectively generates the multibinding expression. /// </summary> /// <param name="serviceProvider">Service provider given by the framework.</param> /// <returns>A new <see cref="MultiBindingExpression"/> object.</returns> public override object ProvideValue(IServiceProvider serviceProvider) { var result = base.ProvideValue(serviceProvider); // Check each item property source: foreach (var item in Bindings) { if (getBindingSourcePropertyValue(item as Binding, serviceProvider) is INotifyCollectionChanged collection) { CollectionChangedEventManager.AddListener(collection, this); // add this as listener to update collection when it changes } } // For all target element related to an 'unresolved' binding during the // previous method call (normaly only one), register to loaded event so we will // add the listener once the visual tree is constructed: foreach (var unresolvedtarget in UnresolvedBindings.Values.Distinct()) { unresolvedtarget.Loaded += Unresolvedtarget_Loaded; } foreach (var datacontextTarget in DataContextBindings.Values.Distinct()) { datacontextTarget.DataContextChanged += DatacontextTarget_DataContextChanged; } return(result); }
public ExceptViewAdapter(InputCollectionWrapper <T> input1, InputCollectionWrapper <T> input2, LinqContinuousCollection <T> output) { if (input1 == null) { throw new ArgumentNullException("input1"); } if (input2 == null) { throw new ArgumentNullException("input2"); } if (output == null) { throw new ArgumentNullException("output"); } this.Input1 = input1; this.Input2 = input2; this.Output = new OutputCollectionWrapper <T>(output); // Backreference output.SourceAdapter = this; // Subscribe to collection / property change CollectionChangedEventManager.AddListener(input1.InnerAsNotifier, this); CollectionChangedEventManager.AddListener(input2.InnerAsNotifier, this); // Evaluate changes ReEvaluate(); }
private SetDifferenceReadOnlyObservableList(IEnumerable <T> originalSource, IEnumerable <T> substractedSource, IEqualityComparer <T> comparer, ObservableDictionary <T, RefCountItemContainer <T> > containers) : base( new FilteredReadOnlyObservableList <RefCountItemContainer <T> >(containers.Values, container => container.CountOnFirst > 0 && container.CountOnSecond == 0, new ContainerEqualityComparer <T, RefCountItemContainer <T> >(comparer), nameof(RefCountItemContainer <T> .CountOnFirst), nameof(RefCountItemContainer <T> .CountOnSecond)) .ListSelect(container => container.Item)) { _originalSource = originalSource; _containers = containers; _substractedSource = substractedSource; AddRange(_containers, _substractedSource, RefCountItemContainer <T> .CreateFromSecond); AddRange(_containers, _originalSource, RefCountItemContainer <T> .CreateFromFirst); var originalNotify = _originalSource as INotifyCollectionChanged; if (originalNotify != null) { CollectionChangedEventManager.AddListener(originalNotify, this); } var substractedNotify = _substractedSource as INotifyCollectionChanged; if (substractedNotify != null) { CollectionChangedEventManager.AddListener(substractedNotify, this); } }
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue) { base.OnItemsSourceChanged(oldValue, newValue); var oldCollection = oldValue as INotifyCollectionChanged; var newCollection = newValue as INotifyCollectionChanged; if (oldCollection != null) { CollectionChangedEventManager.RemoveListener(oldCollection, this); } if (newCollection != null) { CollectionChangedEventManager.AddListener(newCollection, this); } if (!this.IsInitialized) { return; } if (!VirtualizingStackPanel.GetIsVirtualizing(this) || (VirtualizingStackPanel.GetIsVirtualizing(this) && (newValue != null))) { this.RemoveUnavailableSelectedItems(); } this.UpdateSelectedMemberPathValuesBindings(); this.UpdateValueMemberPathValuesBindings(); }
/// <summary> /// Called whenever the datacontext of one of the inner source binding changed. /// </summary> /// <param name="sender">A framework element for which the property changed.</param> /// <param name="e">Information about the datacontext changed event.</param> private void DatacontextTarget_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (sender is FrameworkElement casted) { // Only if extension is still alive: if (IsExtensionValid) { // Loop through every bindings set on datacontext that we registered, // and hook to collection change event for the new datacontext value: foreach (var binding in DataContextBindings.Keys) { if (DataContextBindings[binding] == casted) { if (BindingHelpers.ResolvePathValue(casted.DataContext, binding.Path) is INotifyCollectionChanged collection) { CollectionChangedEventManager.AddListener(collection, this); } } } } else { casted.DataContextChanged -= DatacontextTarget_DataContextChanged; } } }
private static void OnDataGridContextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { GroupLevelIndicatorPane self = sender as GroupLevelIndicatorPane; if (self != null) { DataGridContext dataGridContext = e.OldValue as DataGridContext; //unregister to the old contexts Collection GroupDescriptions Changed event if (dataGridContext != null) { CollectionChangedEventManager.RemoveListener(dataGridContext.Items.GroupDescriptions, self); } dataGridContext = e.NewValue as DataGridContext; //register to the new contexts Collection GroupDescriptions Changed event if (dataGridContext != null) { CollectionChangedEventManager.AddListener(dataGridContext.Items.GroupDescriptions, self); self.PrepareDefaultStyleKey(dataGridContext.DataGridControl.GetView()); } self.InvalidateMeasure(); } }
/// <summary> /// Handles a change to the Columns property. /// </summary> /// <param name="dependencyObject">The DependancyObject that owns the property.</param> /// <param name="dependencyPropertyChangedEventArgs">The DependencyProperty that has changed.</param> static void OnColumnsPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { // The listener is the object that owns the Columns property. ColumnViewRowPresenterBase columnViewRowPresenterBase = dependencyObject as ColumnViewRowPresenterBase; // This will disconnect the old listener from getting changes to the columns. ColumnViewColumnCollection oldCollection = dependencyPropertyChangedEventArgs.OldValue as ColumnViewColumnCollection; if (oldCollection != null) { // This will disconnect the RowPresenter from changes made to the old column collection. CollectionChangedEventManager.RemoveListener(oldCollection, columnViewRowPresenterBase); // This will clear out any items from the old collection. This is preferrable to a collection 'Reset' because we can provide the columns that have // gone out of scope which might not be available any other way. columnViewRowPresenterBase.OnColumnCollectionChanged( columnViewRowPresenterBase, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldCollection)); } // This will connect the new listener to get changes to the columns. ColumnViewColumnCollection newCollection = dependencyPropertyChangedEventArgs.NewValue as ColumnViewColumnCollection; if (newCollection != null) { // This will connect the RowPresenter to the collection of columns so that any changes made to the column set is reflected in the arrangement of // cells in the view. CollectionChangedEventManager.AddListener(newCollection, columnViewRowPresenterBase); // This will syncrhonize the view to the new column set. columnViewRowPresenterBase.OnColumnCollectionChanged( columnViewRowPresenterBase, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newCollection)); } }
protected SmartViewAdapter(InputCollectionWrapper <TInput> input, LinqContinuousCollection <TOutput> output, HashSet <string> monitoredProperties) { if (input == null) { throw new ArgumentNullException("input"); } if (output == null) { throw new ArgumentNullException("output"); } _input = input; _output = new OutputCollectionWrapper <TOutput>(output); _monitoredProperties = monitoredProperties; output.SourceAdapter = this; // Must be referenced by this instance: foreach (TInput item in _input.InnerAsList) { SubscribeToItem(item); } CollectionChangedEventManager.AddListener( _input.InnerAsNotifier, this); }
/// <summary> /// Initializes a new instance of the <see cref="ListSync{TSource,TDestination}"/> class. /// </summary> /// <param name="sourceList">The source list.</param> /// <param name="destList">The destination list.</param> /// <param name="destItemFactory">Factory method which creates a TDestination for a given TSource.</param> /// <param name="destItemRemover">Method called when a TDestination is removed.</param> public ListSync(IEnumerable sourceList, IList <TDestination> destList, Func <TSource, TDestination> destItemFactory, Action <TDestination> destItemRemover) { _destItemFactory = destItemFactory; _destItemRemover = destItemRemover; if (sourceList == null) { throw new ArgumentNullException("sourceList"); } if (destList == null) { throw new ArgumentNullException("destList"); } _sourceList = sourceList; _destList = destList; var notifier = _sourceList as INotifyCollectionChanged; if (notifier != null) { _collectionObserver = new WeakEventListener <NotifyCollectionChangedEventArgs>(SourceCollection_CollectionChanged); CollectionChangedEventManager.AddListener(notifier, _collectionObserver); } PopulateWithAllItems(); }
/// <summary> /// Initializes a new instance of the <see cref="TransposedItemsSource"/> class. /// </summary> /// <param name="source">The <see cref="IEnumerable"/>.</param> public TransposedItemsSource(IEnumerable source) { if (source is null) { throw new ArgumentNullException(nameof(source)); } this.source = new WeakReference(source); var type = source.GetElementType(); this.Properties = TypeDescriptor.GetProperties(type); this.rows = this.Properties.OfType <PropertyDescriptor>() .Select(x => new TransposedRow(this, x)) .ToList(); this.IsReadOnly = this.Properties.OfType <PropertyDescriptor>() .Any(x => !x.IsReadOnly); if (source is INotifyCollectionChanged incc) { CollectionChangedEventManager.AddListener(incc, this); } foreach (var inpc in this.Source.OfType <INotifyPropertyChanged>()) { PropertyChangedEventManager.AddListener(inpc, this, string.Empty); } }
public CollectionMerger(IList <T> source, ICollection <T> target, int index = -1) { if (source == null || target == null) { throw new ArgumentNullException("The collections of CollectionMerge should not be null"); } if (index < 0) { _insertIndex = source.Count; target.Apply(item => source.Add(item)); } else { _insertIndex = index; target.Apply(item => { source.Insert(index, item); index++; }); } INotifyCollectionChanged collection = target as INotifyCollectionChanged; if (collection != null) { _source = new WeakReference(source); CollectionChangedEventManager.AddListener(collection, this); } }
/// <summary> /// Initializes a new instance of the <see cref="DictionaryCollectionBase{T}"/> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="items">The items.</param> protected DictionaryCollectionBase(ObservableDictionary <TKey, TValue> owner, ICollection <T> items) { _items = items; Owner = owner; CollectionChangedEventManager.AddListener(Owner, this); PropertyChangedEventManager.AddListener(Owner, this, nameof(Count)); }
/// <summary> /// Initializes a new instance of the <see cref="ConverterCollection<TNew, TOld>"/> class. /// </summary> /// <param name="originalCollection">The original collection.</param> /// <param name="converter">The converter used to create the elements in this collection.</param> public ConverterCollection(IEnumerable <TOld> originalCollection, Func <TOld, TNew> converter) : base(new ObservableCollection <TNew>()) { if (originalCollection == null) { throw new ArgumentNullException("originalCollection"); } if (converter == null) { throw new ArgumentNullException("converter"); } this.mapping = new List <Tuple <TOld, TNew> >(); this.originalCollection = originalCollection; this.converter = converter; this.newItemComparer = EqualityComparer <TNew> .Default; this.oldItemComparer = EqualityComparer <TOld> .Default; INotifyCollectionChanged collectionChanged = originalCollection as INotifyCollectionChanged; if (collectionChanged != null) { CollectionChangedEventManager.AddListener(collectionChanged, this); } innerCollection = (ObservableCollection <TNew>) this.Items; foreach (TOld item in originalCollection) { innerCollection.Add(ConvertItem(item)); } }
private DistinctReadOnlyObservableCollection(IReadOnlyObservableCollection <T> source, ObservableDictionary <T, int> containers) : base(containers.Keys) { _source = source; _containers = containers; AddRange(_containers, _source); CollectionChangedEventManager.AddListener(_source, this); }
protected void ListenForChangeEvents(IList list) { if (!(list is INotifyCollectionChanged)) { return; } CollectionChangedEventManager.AddListener(list as INotifyCollectionChanged, (IWeakEventListener)this); }
protected override void OnModelItemChanged(object newItem) { base.OnModelItemChanged(newItem); ModelItemCollection elements = ModelItem.Properties["Elements"].Collection; //NOXLATE CollectionChangedEventManager.AddListener(elements, _collectionChangedListener); }
private void timeline_TimelineReady( object sender, EventArgs e ) { timeline.ResetEvents(Resource.Monet); CollectionChangedEventManager.AddListener(timeline.SelectedTimelineEvents, this); }
public ScheduleEntriesDesignViewModel(IBAWindow parentView, ScheduleEntriesCalendar calendar) { this.calendar = calendar; this.parentView = parentView; CollectionChangedEventManager.AddListener(ActivitiesReposidory.Instance, this); CollectionChangedEventManager.AddListener(CustomerGroupsReposidory.Instance, this); CollectionChangedEventManager.AddListener(CustomersReposidory.Instance, this); }
/// <summary> /// Listens for change events on a list. /// </summary> /// <param name="list">The list to listen to.</param> protected void ListenForChangeEvents(IList list) { var source = list as INotifyCollectionChanged; if (source != null) { CollectionChangedEventManager.AddListener(source, this); } }
protected override void InsertItem(int index, IEnumerable <Location> polygon) { if (polygon is INotifyCollectionChanged observablePolygon) { CollectionChangedEventManager.AddListener(observablePolygon, this); } base.InsertItem(index, polygon); }
/// <summary> /// Initializes a new instance of the <see cref="CollectionSelector{T}" /> class. /// </summary> /// <param name="items">The source items.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="items" /> is <strong>null</strong>.</exception> public CollectionSelector(IReadOnlyObservableList <T> items) { if (items == null) { throw new ArgumentNullException(nameof(items)); } Items = items; CollectionChangedEventManager.AddListener(Items, this); }
private void RegisterCollectionChanged(INotifyCollectionChanged collection) { if (collection == null) { return; } CollectionChangedEventManager.AddListener(collection, this); }
public EnumerableWrapper(IEnumerable source) { _source = source; RefreshList(); if (_source is INotifyCollectionChanged notifyCollection) { CollectionChangedEventManager.AddListener(notifyCollection, this); } }
private void AdoptSourceCollection() { var notifyChangedCollection = this.sourceCollection as INotifyCollectionChanged; if (notifyChangedCollection != null) { CollectionChangedEventManager.AddListener(notifyChangedCollection, this); } }
public usrSupplementsCyclesView() { InitializeComponent(); DataContext = this; MainWindow.Instance.EnsureAnchorable(Strings.usrWorkoutCommentsList_Header_Comments, "pack://application:,,,/BodyArchitect.Client.Resources;component/Images/Comments16.png", "RatingsCommentsControl", AnchorableShowStrategy.Right); CollectionChangedEventManager.AddListener(SupplementsCycleDefinitionsReposidory.Instance, this); }
private void Subscribe(ICollection collection) { var notifierCollection = collection as INotifyCollectionChanged; if (notifierCollection != null) { CollectionChangedEventManager.AddListener(notifierCollection, this); } }
internal void LinkVirtualListAndCollectionViewGroup(VirtualList virtualItemList, DataGridVirtualizingCollectionViewGroupBase collectionViewGroup) { Debug.Assert(!m_virtualListVSCollectionViewGroupDictionary.ContainsKey(virtualItemList)); Debug.Assert(!m_virtualListVSCollectionViewGroupDictionary.ContainsValue(collectionViewGroup)); m_virtualListVSCollectionViewGroupDictionary.Add(virtualItemList, collectionViewGroup); CollectionChangedEventManager.AddListener(virtualItemList, collectionViewGroup); }
public BetterListCollectionView([NotNull] IList list) : base(list) { if (list is INotifyCollectionChanged changed) { changed.CollectionChanged -= OnCollectionChanged; CollectionChangedEventManager.AddListener(changed, this); } }