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

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

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

            int newViewIndex = _view.Count;

            if (_sortDescriptions.Any())
            {
                _sortProperties.Clear();
                newViewIndex = _view.BinarySearch(newItem, this);
                if (newViewIndex < 0)
                {
                    newViewIndex = ~newViewIndex;
                }
            }
            else if (_filter != null)
            {
                if (_source is 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++;
            }

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

            OnVectorChanged(e);
            return(true);
        }