private void UpdateItem(OrderedListInternal <int, T> filterCollection, NotifyCollectionChangedEventArgs e, NotificationType notificationType)
        {
            int filterIndex;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                var item = (T)e.NewItems[0];
                UpdateFilterItems(filterCollection, e.NewStartingIndex, 1);

                if (!_filter(item))
                {
                    return;
                }
                filterIndex = filterCollection.Add(e.NewStartingIndex, item);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, filterIndex), notificationType);
                break;

            case NotifyCollectionChangedAction.Remove:
                filterIndex = filterCollection.IndexOfKey(e.OldStartingIndex);
                UpdateFilterItems(filterCollection, e.OldStartingIndex, -1);
                if (filterIndex == -1)
                {
                    return;
                }
                filterCollection.RemoveAt(filterIndex);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, e.OldItems[0], filterIndex), notificationType);
                break;

            case NotifyCollectionChangedAction.Replace:
                filterIndex = filterCollection.IndexOfKey(e.NewStartingIndex);
                if (filterIndex == -1)
                {
                    return;
                }

                var newItem = (T)e.NewItems[0];
                if (_filter(newItem))
                {
                    T oldItem = filterCollection.GetValue(filterIndex);
                    filterCollection.Values[filterIndex] = newItem;
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, e.NewItems[0], oldItem, filterIndex), notificationType);
                }
                else
                {
                    T oldValue = filterCollection.GetValue(filterIndex);
                    filterCollection.RemoveAt(filterIndex);
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldValue, filterIndex), notificationType);
                }
                break;

            default:
                UpdateFilterInternal(filterCollection, _filter, notificationType);
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Updates a filter.
        /// </summary>
        protected virtual void UpdateFilterInternal(out bool shouldRaiseEvents)
        {
            FilterDelegate <T> currentFilter = _filter;

            if (currentFilter != null)
            {
                _filterCollection.Clear();
                for (int index = 0; index < Items.Count; index++)
                {
                    T item = Items[index];
                    if (currentFilter(item))
                    {
                        _filterCollection.Add(index, item);
                    }
                }
            }
            EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            shouldRaiseEvents = true;
        }
        private void UpdateFilterInternal(OrderedListInternal <int, T> filterCollection, FilterDelegate <T> filter, NotificationType notificationType)
        {
            var currentFilter = filter;

            filterCollection.Clear();
            var items = GetItems();

            if (currentFilter != null)
            {
                for (var index = 0; index < items.Count; index++)
                {
                    var item = items[index];
                    if (currentFilter(item))
                    {
                        filterCollection.Add(index, item);
                    }
                }
            }
            OnCollectionChanged(Empty.ResetEventArgs, notificationType);
        }