private void SetAllergens() { List <Allergen> allergens = LocalDatabase.AllergensList; groupedAll = new ObservableCollection <GroupedAllergen>(); foreach (Allergen allergen in allergens) { if (allergen.IsCategory) { GroupedAllergen group = new GroupedAllergen(); group.Expanded = true; group.Selected = allergen.Selected; group.GroupName = allergen.DanishName /*.First().ToString().ToUpper()+ allergen.DanishName.Substring(1)*/; foreach (Allergen allergen2 in allergens) { if (allergen2.Category == group.GroupName && !allergen2.IsCategory) { Allergen allergernToAdd = allergen2; allergernToAdd.DanishName = allergen2.DanishName /*.First().ToString().ToUpper() + allergen2.DanishName.Substring(1)*/; group.Add(allergernToAdd); } } if (group.Count > 0) { group.HasChildren = true; } groupedAll.Add(group); } } }
private void updateList() { groupedExpanded = new ObservableCollection <GroupedAllergen>(); foreach (GroupedAllergen headerGroup in groupedAll) { GroupedAllergen newGroup = new GroupedAllergen { GroupName = headerGroup.GroupName, Expanded = headerGroup.Expanded, HasChildren = headerGroup.HasChildren, Selected = headerGroup.Selected }; if (headerGroup.Expanded) { foreach (Allergen item in headerGroup) { newGroup.Add(item); } } groupedExpanded.Add(newGroup); } allergensListView.ItemsSource = groupedExpanded; }
private void SearchList(String SearchWord) { //recreate the list with allergens that contian the word groupedExpanded = new ObservableCollection <GroupedAllergen>(); foreach (GroupedAllergen headerGroup in groupedAll) { GroupedAllergen newGroup = new GroupedAllergen { GroupName = headerGroup.GroupName, Expanded = headerGroup.Expanded, HasChildren = headerGroup.HasChildren, Selected = headerGroup.Selected }; foreach (Allergen item in headerGroup) { if (item.DanishName.ToLower().Contains(SearchWord.ToLower())) { newGroup.Add(item); } } if (newGroup.Count > 0 || newGroup.GroupName.ToLower().Contains(SearchWord.ToLower())) { groupedExpanded.Add(newGroup); } } allergensListView.ItemsSource = groupedExpanded; }