public void Remove(MeasurementLimit limit) { MeasurementLimits.Remove(limit); MeasurementLimit.AllMeasurementLimits.Remove(limit); SelectedItem = null; }
/// <summary> /// При изменении коллекции городов, обновляю список для поиска городов /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void AllCitiesOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: // если добавление CitiesForFind.Insert(1, e.NewItems[0] as City); break; case NotifyCollectionChangedAction.Remove: // если удаление City city = e.OldItems[0] as City; if (city != null) { for (int i = MeasurementLimits.Count() - 1; i >= 0; i--) { if (MeasurementLimits[i].City.Id == city.Id) { MeasurementLimits.Remove(MeasurementLimits[i]); } } for (int i = MeasurementLimit.AllMeasurementLimits.Count() - 1; i >= 0; i--) { if (MeasurementLimit.AllMeasurementLimits[i].City.Id == city.Id) { MeasurementLimit.AllMeasurementLimits.Remove(MeasurementLimit.AllMeasurementLimits[i]); } } if (CitiesForFind.Contains(city)) { CitiesForFind.Remove(city); } } break; case NotifyCollectionChangedAction.Replace: // если замена CitiesForFind.Remove(e.OldItems[0] as City); CitiesForFind.Insert(1, e.NewItems[0] as City); break; } }