/// <summary> /// Update properties used to display content in the combo box with new values. /// </summary> /// <parameters> /// <param name="enumType">The type of the enum bound to the <see cref="EnumBinding"/> dependency property.</param> /// </parameters> /// <remarks> /// This will display a new set of localized strings in the drop-down part of the combo box, and select one of them if appropriate. /// </remarks> private void UpdateContent(Type enumType) { EnumNameCollection.Clear(); if (enumType != null && enumType.IsEnum) { IValueConverter Converter = NameConverter; object ConverterParameter = NameConverterParameter; ConversionCulture = NameConverterCulture; if (ConversionCulture == null) { ConversionCulture = CultureInfo.CurrentCulture; } string[] EnumNames = enumType.GetEnumNames(); foreach (string EnumName in EnumNames) { string ConvertedText = (Converter != null) ? Converter.Convert(EnumName, typeof(string), ConverterParameter, ConversionCulture) as string : EnumName; EnumNameCollection.Add(ConvertedText); } } ItemsSource = EnumNameCollection; if (SelectedIndex >= EnumNameCollection.Count) { SelectedIndex = -1; } }
/// <summary> /// Resets properties used to display content in the combo box. /// </summary> private void ResetContent() { EnumNameCollection.Clear(); SelectedIndex = -1; }