/// <summary> /// If the CanSearch() returns true it will search the ContactList collection depending on /// what is selected in the combo box and the content of the text box /// </summary> /// <param name="obj"></param> private void Search(object obj) { if (string.IsNullOrEmpty(SearchTextBox)) { LoadContactList(); } else { filtered = new HashSet <ContactModel>(); foreach (ContactModel contact in ContactList) { if (SearchComboBox.Contains("First Name")) { if (contact.FirstName.ToLower().Contains(SearchTextBox.ToLower())) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Last Name")) { if (contact.LastName.ToLower().Contains(SearchTextBox.ToLower())) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Last Name")) { if (contact.LastName.ToLower().Contains(SearchTextBox.ToLower())) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Address")) { if (contact.FullAddress.ToLower().Contains(SearchTextBox.ToLower())) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Mobile Phone")) { if (contact.MobilePhone.Contains(SearchTextBox)) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Land Line")) { if (contact.LandLine.Contains(SearchTextBox)) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Email")) { if (contact.EmailAddress.ToLower().Contains(SearchTextBox.ToLower())) { filtered.Add(contact); } } else if (SearchComboBox.Contains("Date of Birth")) { if (contact.DateOfBirth.ToString().Contains(SearchTextBox)) { filtered.Add(contact); } } } ContactList = new ObservableCollection <ContactModel>(); foreach (ContactModel contact in filtered) { ContactList.Add(contact); } } }