public void DoSearch() { foreach (var card in Cards) { card.IsDisplayed = true; } foreach (var card in Cards) { var isNameMatch = string.IsNullOrEmpty(CardNameSearch) ? true : card.Info.Name.ToLower().Contains(CardNameSearch.ToLower()); var isPatchMatch = string.IsNullOrEmpty(PatchSearch) ? true : card.Info.Patch.Contains(PatchSearch); var isNpcMatch = string.IsNullOrEmpty(NPCNameSearch) ? true : card.Info.NPCs.FirstOrDefault(n => n.ToLower().Contains(NPCNameSearch.ToLower())) != null; var isMinDifficultyMatch = string.IsNullOrEmpty(MinDifficultySearch) ? true : card.Difficulty >= int.Parse(MinDifficultySearch); var isMaxDifficultyMatch = string.IsNullOrEmpty(MaxDifficultySearch) ? true : card.Difficulty <= int.Parse(MaxDifficultySearch); var isCollectionMatch = string.IsNullOrEmpty(CollectedSearch) || CollectedSearch == "No Preference" ? true : (CollectedSearch == "Collected" && card.IsCollected) || (CollectedSearch == "Uncollected" && !card.IsCollected); card.IsDisplayed = isNameMatch && isPatchMatch && isNpcMatch && isMinDifficultyMatch && isMaxDifficultyMatch && isCollectionMatch; } // store fields for resetting later var cardName = CardNameSearch; var patch = PatchSearch; var npcName = NPCNameSearch; CardNames.Clear(); Patches.Clear(); NPCNames.Clear(); var displayedCards = Cards.Where(c => c.IsDisplayed); foreach (var displayedCard in displayedCards) { if (!CardNames.Contains(displayedCard.Info.Name)) { CardNames.Add(displayedCard.Info.Name); } if (!Patches.Contains(displayedCard.Info.Patch)) { Patches.Add(displayedCard.Info.Patch); } foreach (var npc in displayedCard.Info.NPCs) { if (!NPCNames.Contains(npc)) { NPCNames.Add(npc); } } } // set fields back after the search CardNameSearch = cardName; PatchSearch = patch; NPCNameSearch = npcName; }