/// <summary> /// Load each elements from the ItemsSource to the ComboBox /// </summary> private void LoadElementsToControl() { ListElementsWithAll.Clear(); if (this.ItemsSource.ToList().Count > 0) { ListElementsWithAll.Add(new SearchElement(All)); // Add an element to select everything } foreach (SearchElement elem in this.ItemsSource) { ListElementsWithAll.Add(elem); } MultiSelectCombox.ItemsSource = ListElementsWithAll; // Load the list to the ComboBox }
/// <summary> /// Automatically select the "All element" according to whether the other elements are selected /// </summary> private void VerifyIfAllElementsAreSelected() { int _selectedCount = 0; foreach (SearchElement elem in ListElementsWithAll) { if (elem.IsSelected && elem.Name != All) { _selectedCount++; } } if (_selectedCount == ListElementsWithAll.Count - 1) { ListElementsWithAll.FirstOrDefault(i => i.Name == All).IsSelected = true; } else { ListElementsWithAll.FirstOrDefault(i => i.Name == All).IsSelected = false; } }