/// <summary> /// Handle the selected index changing. If the checkbox for the new selection isn't checked, check it. Leave all the other checkboxes alone. /// </summary> /// <param name="sender">The MultiComboBox.</param> /// <param name="eventArgs">The event arguments.</param> private static void OnSelectedIndexChanged(object sender, DependencyPropertyChangedEventArgs eventArgs) { MultiComboBox comboBox = sender as MultiComboBox; if (comboBox.SelectedIndex >= 0 && !comboBox.SelectedItems.Contains(comboBox.listBox.Items[comboBox.SelectedIndex])) { comboBox.listBox.SelectedIndex = comboBox.SelectedIndex; } }
/// <summary> /// Handle the separator changing. Update the display text. /// </summary> /// <param name="sender">The MultiComboBox.</param> /// <param name="eventArgs">The event arguments.</param> private static void OnSeparatorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs) { MultiComboBox comboBox = sender as MultiComboBox; if (comboBox.IsLoaded) { comboBox.ResetDisplay(); } }
/// <summary> /// Deceit. Rather than allowing the value of SelectedValues to change, simply duplicate the contents of the incoming list to our internal /// list. /// </summary> /// <param name="sender">The MultiComboBox.</param> /// <param name="newValue">The incoming list.</param> /// <returns>The combobox's selectedItems list.</returns> private static object CoerceSelectedValues(DependencyObject sender, object newValue) { MultiComboBox comboBox = sender as MultiComboBox; // The first time through we're actually setting SelectedValues to the private selectedValues list, so we'll let it get set. if (!comboBox.initialized) { return(newValue); } else { comboBox.selectedValues.Clear(); if (newValue != null) { foreach (object value in newValue as IList) { comboBox.selectedValues.Add(value); } } return(comboBox.selectedValues); } }