Beispiel #1
0
        private void HandleItemRemoved(int oldStartingIndex, object oldItem)
        {
            if (_filter != null && !_filter(oldItem))
            {
                return;
            }

            if (oldStartingIndex < 0 || oldStartingIndex >= _view.Count || !Equals(_view[oldStartingIndex], oldItem))
            {
                oldStartingIndex = _view.IndexOf(oldItem);
            }

            if (oldStartingIndex < 0)
            {
                return;
            }

            _view.RemoveAt(oldStartingIndex);
            if (oldStartingIndex <= _index)
            {
                _index--;
            }

            var e = new VectorChangedEventArgs(CollectionChange.ItemRemoved, oldStartingIndex, oldItem);

            OnVectorChanged(e);
        }
Beispiel #2
0
        private void RemoveFromView(int itemIndex, object item)
        {
            _view.RemoveAt(itemIndex);
            if (itemIndex <= CurrentPosition)
            {
                CurrentPosition--;
            }

            var e = new VectorChangedEventArgs(CollectionChange.ItemRemoved, itemIndex, item);

            OnVectorChanged(e);
        }
Beispiel #3
0
        private void HandleItemAdded(int newStartingIndex, object newItem)
        {
            if (_filter != null && !_filter(newItem))
            {
                return;
            }

            if (_sortDescriptions.Any())
            {
                _sortProperties.Clear();
                newStartingIndex = _view.BinarySearch(newItem, this);
                if (newStartingIndex < 0)
                {
                    newStartingIndex = ~newStartingIndex;
                }
            }
            else if (_filter != null)
            {
                if (_sourceList == null)
                {
                    HandleSourceChanged();
                    return;
                }

                var visibleBelowIndex = 0;
                for (var i = newStartingIndex; i < _sourceList.Count; i++)
                {
                    if (!_filter(_sourceList[i]))
                    {
                        visibleBelowIndex++;
                    }
                }

                newStartingIndex = _view.Count - visibleBelowIndex;
            }

            _view.Insert(newStartingIndex, newItem);
            if (newStartingIndex <= _index)
            {
                _index++;
            }

            var e = new VectorChangedEventArgs(CollectionChange.ItemInserted, newStartingIndex, newItem);

            OnVectorChanged(e);
        }
Beispiel #4
0
        private bool HandleItemAdded(int newStartingIndex, object newItem, int?viewIndex = null)
        {
            if (_filter != null && !_filter(newItem))
            {
                return(false);
            }

            var newViewIndex = _view.Count;

            if (_sortDescriptions.Any())
            {
                _sortProperties.Clear();
                newViewIndex = _view.BinarySearch(newItem, this);
                if (newViewIndex < 0)
                {
                    newViewIndex = ~newViewIndex;
                }
            }
            else if (_filter != null)
            {
                if (_source == null)
                {
                    HandleSourceChanged();
                    return(false);
                }

                if (newStartingIndex == 0 || _view.Count == 0)
                {
                    newViewIndex = 0;
                }
                else if (newStartingIndex == _source.Count - 1)
                {
                    newViewIndex = _view.Count - 1;
                }
                else if (viewIndex.HasValue)
                {
                    newViewIndex = viewIndex.Value;
                }
                else
                {
                    for (int i = 0, j = 0; i < _source.Count; i++)
                    {
                        if (i == newStartingIndex)
                        {
                            newViewIndex = j;
                            break;
                        }

                        if (_view[j] == _source[i])
                        {
                            j++;
                        }
                    }
                }
            }

            _view.Insert(newViewIndex, newItem);
            if (newViewIndex <= CurrentPosition)
            {
                CurrentPosition++;
            }

            var e = new VectorChangedEventArgs(CollectionChange.ItemInserted, newViewIndex, newItem);

            OnVectorChanged(e);
            return(true);
        }