private void UpdateCollection() { ObservablePersons.Clear(); foreach (var item in Persons) { ObservablePersons.Add(item); } }
private void RealSeach_Execute() { if (SearchText != "" && SearchText != null && SelectedAttribute != "") { ObservablePersons.Clear(); switch (SelectedAttribute) { case "Имя": foreach (var item in Persons.Where(x => x.Name.StartsWith(SearchText))) { ObservablePersons.Add(item); } RaisePropertyChanged("ObservablePersons"); break; case "Фамилия": foreach (var item in Persons.Where(x => x.Surname.StartsWith(SearchText))) { ObservablePersons.Add(item); } RaisePropertyChanged("ObservablePersons"); break; case "Отчество": foreach (var item in Persons.Where(x => x.Middlename.StartsWith(SearchText))) { ObservablePersons.Add(item); } RaisePropertyChanged("ObservablePersons"); break; case "Возраст": foreach (var item in Persons.Where(x => x.Age == Convert.ToInt32(SearchText))) { ObservablePersons.Add(item); } RaisePropertyChanged("ObservablePersons"); break; default: break; } } else { UpdateCollection(); } }