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);
     });
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
            /// <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);
                }
            }
Esempio n. 4
0
            /// <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);
                }
            }
Esempio n. 5
0
        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]);
        }
Esempio n. 6
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]);
        }
Esempio n. 7
0
 private static void OnDetachParentCollectionChanged(CollectionChangedListener listener, INotifyCollectionChanged source)
 {
     source.CollectionChanged -= listener.OnEvent;
 }
Esempio n. 8
0
 private static void OnDetachAggregateResultsCollectionChanged(CollectionChangedListener listener, INotifyCollectionChanged source)
 {
     source.CollectionChanged -= listener.OnEvent;
 }
Esempio n. 9
0
        /// <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;
        }
Esempio n. 10
0
        /// <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;
            }
        }
Esempio n. 11
0
            /// <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;
            }
Esempio n. 12
0
 private static void SetCollectionChangedListener(BindableObject bindable, CollectionChangedListener value) => bindable.SetValue(CollectionChangedListenerProperty, value);