public void DeleteSpectrums() { // .ToList() conversion is important here, as the code itself will modify // the elements of the original collection (ToList() instatinates a copy of the collection) foreach (var selectedSpectrum in SelectedSpectrums.ToList()) { Database.GetConnection().Delete(selectedSpectrum); SelectedSpectrums.Remove(selectedSpectrum); PreparedForImport.Remove(selectedSpectrum); Spectrums.Remove(selectedSpectrum); } }
public void Spectrums_SelectionChanged(SelectionChangedEventArgs args) { SelectedSpectrums.AddRange(args.AddedItems.Cast <object>().Where(x => x is SpectrumBase).Cast <SpectrumBase>()); args.RemovedItems.Cast <object>().Where(x => x is SpectrumBase).Cast <SpectrumBase>().ToList().ForEach(x => SelectedSpectrums.Remove(x)); NotifyOfPropertyChange(() => CanDeleteSpectrums); NotifyOfPropertyChange(() => CanImportToWorkspace); }