static void Main(string[] args) { List <string> list = new List <string>(); list.Add("involve"); list.Add("this"); list.Add("another"); list.Add("direct"); list.Add("finding"); list.Add("returns"); list.Add("means"); list.Add("customers"); list.Add("elements"); list.Add("operation"); list.Add("earlier"); list.Add("dictionary"); list.Add("identifies"); list.Add("store"); list.Add("specify"); ObservableCollection <AdresViewModel> ListaAdresow = new ObservableCollection <AdresViewModel>(); for (int i = list.Count - 1; i >= 0; i--) { AdresViewModel dodatek = new AdresViewModel(list[i], true, false); ListaAdresow.Add(dodatek); Console.WriteLine(dodatek.AdresMailowy); } //lista adresów zaludniona ObservableCollection <AdresViewModel> wyniki = new ObservableCollection <AdresViewModel>(); string szukana; Console.WriteLine("wpisz szukaną:"); szukana = Console.ReadLine(); for (int i = ListaAdresow.Count - 1; i >= 0; i--) { if (ListaAdresow[i].AdresMailowy.Contains(szukana)) { wyniki.Add(ListaAdresow[i]); } } for (int i = wyniki.Count - 1; i >= 0; i--) { Console.WriteLine(wyniki[i].AdresMailowy); } Console.ReadKey(); }
private void ModelSynchro(object sender, NotifyCollectionChangedEventArgs e) //wywołuje akcję, wchodzimy przez CopyPersons() { switch (e.Action) { //nazwy metod jak w modelu: DelPerson i NewPerson //NotifyCollectionChangedAction opisuje akcje które spowodowały CollectionChanged event case NotifyCollectionChangedAction.Add: //Describes the action that caused a System.Collections.Specialized.INotifyCollectionChanged.CollectionChanged AdresViewModel newTask = (AdresViewModel)e.NewItems[0]; //NewItems otrzymuje listę nowych rzeczy powodujących zmianę. if (newTask != null) //jeśli wciąż są nowe itmey... { model.DodajAdres(newTask.GetModel()); //w kolekcji jest tworzone nowe wywołanie modelu } break; case NotifyCollectionChangedAction.Remove: //j.w. tylko dla usuwania AdresViewModel removeTask = (AdresViewModel)e.OldItems[0]; if (removeTask != null) { model.UsunAdres(removeTask.GetModel()); } break; } }