private void ItemsSourceOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: for (var i = 0; i < e.NewItems.Count; ++i) { var model = (IDataSourceViewModel)e.NewItems[i]; if (PassesFilter(model)) { var sourceIndex = e.NewStartingIndex + i; var filteredIndex = FindFilteredIndex(sourceIndex); FilteredItemsSource.Insert(filteredIndex, model); } } break; case NotifyCollectionChangedAction.Remove: foreach (IDataSourceViewModel model in e.OldItems) { FilteredItemsSource.Remove(model); } break; case NotifyCollectionChangedAction.Reset: FilteredItemsSource.Clear(); break; default: throw new NotImplementedException(); } UpdateNoDataSourcesMessage(); }
private void OnStringFilterChanged(string oldValue, string newValue) { if (ItemsSource != null) { int sourceIndex = 0; int filterIndex = 0; foreach (IDataSourceViewModel model in ItemsSource) { bool passedOld = PassesFilter(model, oldValue); bool passesNew = PassesFilter(model, newValue); if (!passedOld) { if (passesNew) { FilteredItemsSource.Insert(filterIndex++, model); } } else if (!passesNew) { FilteredItemsSource.RemoveAt(filterIndex); } else { ++filterIndex; } ++sourceIndex; } } }
private void OnStringFilterChanged(string oldValue, string newValue) { if (ItemsSource != null) { var sourceIndex = 0; var filterIndex = 0; foreach (var model in ItemsSource) { var passedOld = PassesFilter(model, oldValue); var passesNew = PassesFilter(model, newValue); if (!passedOld) { if (passesNew) { FilteredItemsSource.Insert(filterIndex++, model); } } else if (!passesNew) { FilteredItemsSource.RemoveAt(filterIndex); } else { ++filterIndex; } ++sourceIndex; } } UpdateNoDataSourcesMessage(); }
private void ItemsSourceOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: for (int i = 0; i < e.NewItems.Count; ++i) { var model = (IDataSourceViewModel)e.NewItems[i]; if (PassesFilter(model)) { int sourceIndex = e.NewStartingIndex + i; int filteredIndex = FindFilteredIndex(sourceIndex); FilteredItemsSource.Insert(filteredIndex, model); } } break; case NotifyCollectionChangedAction.Remove: foreach (IDataSourceViewModel model in e.OldItems) { FilteredItemsSource.Remove(model); } break; /*case NotifyCollectionChangedAction.Reset: * foreach (IDataSourceViewModel model in _dataSourceCopy) * { * model.PropertyChanged -= DataSourceOnPropertyChanged; * } * _dataSourceCopy.Clear(); * FilteredItemsSource.Clear(); * break;*/ default: throw new NotImplementedException(); } }