protected override void OnAttached() { base.OnAttached(); _itemChangedListener = new CollectionChangedListener(AssociatedObject.Items, (s, e) => { var lastItem = AssociatedObject.Items.Cast <object>().LastOrDefault(); if (lastItem == null) { return; } AssociatedObject.ScrollIntoView(lastItem); }); }
public void IDataContainer_RaisesCollectionChangedOnClear() { IDataContainer A = DataContainerBuilder.Create() .Data("A", 1) .Data("B", 2) .Build(); var listener = new CollectionChangedListener(A); Assert.Null(listener.LastChange); A.Clear(); Assert.NotNull(listener.LastChange); Assert.Equal(NotifyCollectionChangedAction.Reset, listener.LastChange.Action); }
/// <summary> /// Initializes a new instance of the <see cref="ContainerCollection"/> class. /// </summary> /// <param name="items">The input data objects.</param> /// <param name="converter">The underlying converter.</param> internal ContainerCollection(IList items, ItemsConverter converter) : this(new ObservableCollection <DependencyObject>(converter.GetContainers(items))) { this.converter = converter; propertyListener = new PropertyChangedListener(this); PropertyChangedEvent.AddListener(converter, propertyListener); if (items is INotifyCollectionChanged collection) { this.items = items; collectionListener = new CollectionChangedListener(this); CollectionChangedEvent.AddListener(collection, collectionListener); } }
/// <summary> /// Initializes a new instance of the <see cref="GroupingCollection"/> class. /// </summary> /// <param name="enumerable">The input sequence.</param> /// <param name="grouping">The underlying grouping.</param> internal GroupingCollection(IEnumerable <DependencyObject> enumerable, Grouping grouping) : this(new RecomposableCollection <DependencyObject>(grouping.GroupSort(enumerable))) { this.grouping = grouping; propertyListener = new PropertyChangedListener(this); PropertyChangedEvent.AddListener(grouping, propertyListener); if (enumerable is INotifyCollectionChanged collection) { this.enumerable = enumerable; collectionListener = new CollectionChangedListener(this); CollectionChangedEvent.AddListener(collection, collectionListener); } }
public void IDataContainer_RaisesCollectionChangedOnAdd() { IDataContainer A = DataContainerBuilder.Create().Build(); var listener = new CollectionChangedListener(A); Assert.Null(listener.LastChange); DataObject newObject = DataObjectFactory.GetDataObjectFor("A", 1); A.Add(newObject); Assert.NotNull(listener.LastChange); Assert.Equal(NotifyCollectionChangedAction.Add, listener.LastChange.Action); Assert.Single(listener.LastChange.NewItems); Assert.Same(newObject, listener.LastChange.NewItems[0]); }
public void IDataContainer_RaisesCollectionChangedOnRemove() { IDataContainer A = DataContainerBuilder.Create() .Data("A", 1) .Build(); var listener = new CollectionChangedListener(A); Assert.Null(listener.LastChange); DataObject obj = A.Find("A"); A.Remove(obj); Assert.NotNull(listener.LastChange); Assert.Equal(NotifyCollectionChangedAction.Remove, listener.LastChange.Action); Assert.Single(listener.LastChange.OldItems); Assert.Same(obj, listener.LastChange.OldItems[0]); }
private static void OnDetachParentCollectionChanged(CollectionChangedListener listener, INotifyCollectionChanged source) { source.CollectionChanged -= listener.OnEvent; }
private static void OnDetachAggregateResultsCollectionChanged(CollectionChangedListener listener, INotifyCollectionChanged source) { source.CollectionChanged -= listener.OnEvent; }
/// <summary> /// Adds handler for the <see cref="INotifyCollectionChanged.CollectionChanged"/> event /// of the aggregate result collection. /// </summary> private void ListenAggregateResultsCollectionChangedEvent() { if (!_column.IsAlive) return; var gridControl = ((GridViewColumn) _column.Target).DataControl; if (gridControl == null) return; var collection = gridControl.AggregateResults; _aggregateResultsChangedListener = new CollectionChangedListener(this, collection) { OnEventAction = OnAggregateResultsCollectionChanged, OnDetachAction = OnDetachAggregateResultsCollectionChanged }; collection.CollectionChanged += _aggregateResultsChangedListener.OnEvent; }
/// <summary> /// Sets the parent collection instance. /// </summary> /// <param name="collection">The parent collection instance.</param> public void SetParentCollection(GroupRecordKeyedCollection collection) { if (_parentCollection != null) DetachParentCollection(); _parentCollection = collection; _parentCollectionChangedListener = new CollectionChangedListener(this, _parentCollection) { OnEventAction = OnParentCollectionChanged, OnDetachAction = OnDetachParentCollectionChanged }; _parentCollection.CollectionChanged += _parentCollectionChangedListener.OnEvent; if (ParentGroup != null) { var parentGroupCode = GenerateGroupCode(ParentGroup); GroupRecord parentRecord; _parentCollection.TryGetValue(parentGroupCode, out parentRecord); ParentRecord = parentRecord; } }
/// <summary> /// Adds the process event handlers. /// </summary> private void AddProcessEventHandlers() { var collectionChangedListener = new CollectionChangedListener<ProcessEditFilterSource>(this, _process.FilterList); collectionChangedListener.OnEventAction = OnFilterListChanged; collectionChangedListener.OnDetachAction = Static; _process.FilterList.CollectionChanged += collectionChangedListener.OnEvent; var childChangedListener = new ChildChangedListener<ProcessEditFilterSource>(this, _process.FilterList); childChangedListener.OnEventAction = OnFilterChanged; childChangedListener.OnDetachAction = Static; _process.FilterList.ChildChanged += childChangedListener.OnEvent; }
private static void SetCollectionChangedListener(BindableObject bindable, CollectionChangedListener value) => bindable.SetValue(CollectionChangedListenerProperty, value);