The ranged notify collection changed event args.
상속: System.Collections.Specialized.NotifyCollectionChangedEventArgs
예제 #1
0
        private NotifyRangedCollectionChangedEventArgs CreateEventArgs(NotifyCollectionChangedAction action, IList newItems = null, IList removedItems = null, IList <int> changedIndices = null)
        {
            NotifyRangedCollectionChangedEventArgs eventArgs;

            if (newItems == null && removedItems == null && changedIndices == null)
            {
                eventArgs = new NotifyRangedCollectionChangedEventArgs(action);
            }
            else
            {
                eventArgs = new NotifyRangedCollectionChangedEventArgs(action, newItems, removedItems, changedIndices);
            }

            return(eventArgs);
        }
예제 #2
0
        /// <summary>
        /// Consolidate changed items and indexes from <paramref name="other" /> into <paramref name="instance" /> by append.
        /// </summary>
        /// <param name="instance">The instance</param>
        /// <param name="other">The other instance.</param>
        public static bool ConsolidateItemsByAppend(this NotifyRangedCollectionChangedEventArgs instance, NotifyRangedCollectionChangedEventArgs other)
        {
            if (other.Indices.Count == 0)
            {
                return(false);
            }

            instance.Indices.AddRange(other.Indices);
            foreach (var item in other.ChangedItems)
            {
                instance.ChangedItems.Add(item);
            }

            other.Indices.Clear();
            other.ChangedItems.Clear();

            return(true);
        }
예제 #3
0
        private NotifyRangedCollectionChangedEventArgs CreateEventArgs(NotifyCollectionChangedAction action, T changedItem = default(T), int changedIndex = -1)
        {
            NotifyRangedCollectionChangedEventArgs eventArgs;

            if (changedItem == null)
            {
                eventArgs = new NotifyRangedCollectionChangedEventArgs(action);
            }
            else
            {
                eventArgs = new NotifyRangedCollectionChangedEventArgs(action, new List <T>()
                {
                    changedItem
                }, new List <int>()
                {
                    changedIndex
                });
            }

            return(eventArgs);
        }
예제 #4
0
        /// <summary>
        /// Consolidates changed items and indexes from <paramref name="other" /> into <paramref name="instance" />.
        /// </summary>
        /// <param name="instance">The instance</param>
        /// <param name="other">The other instance.</param>
        /// <returns><c>True</c> if consolidation was executed; otherwise <c>False</c></returns>
        public static bool ConsolidateItems(this NotifyRangedCollectionChangedEventArgs instance, NotifyRangedCollectionChangedEventArgs other)
        {
            if (instance.Indices.Count == 0 || other.Indices.Count == 0)
            {
                return(false);
            }

            if (instance.Indices.Count > other.Indices.Count)
            {
                var backup = instance;
                instance = other;
                other    = backup;
            }

            var consolidated = false;

            for (var i = instance.Indices.Count - 1; i >= 0; i--)
            {
                var idx = other.Indices.IndexOf(instance.Indices[i]);
                while (idx != -1 && !Equals(other.ChangedItems[idx], instance.ChangedItems[i]))
                {
                    idx = other.Indices.IndexOf(instance.Indices[i], idx + 1);
                }

                if (idx != -1)
                {
                    other.Indices.RemoveAt(idx);
                    other.ChangedItems.RemoveAt(idx);

                    instance.Indices.RemoveAt(i);
                    instance.ChangedItems.RemoveAt(i);

                    consolidated = true;
                }
            }

            return(consolidated);
        }