private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var cmb = d as EnumComboBox; var val = e.NewValue as Enum; if (val != null) { var enumType = val.GetType(); if (enumType != cmb.m_CurBoundType) { cmb.m_CurBoundType = enumType; cmb.Items.Clear(); var items = Enum.GetValues(enumType); foreach (Enum item in items) { var visible = true; item.TryGetAttribute <BrowsableAttribute>(a => visible = a.Browsable); if (visible) { var cmbItem = new ComboBoxItem() { ToolTip = EnumControlHelper.GetDescription(item), Content = new EnumComboBoxItem(item, EnumControlHelper.GetTitle(item)), }; cmb.Items.Add(cmbItem); } } } if (!Enum.Equals(e.OldValue, e.NewValue)) { foreach (ComboBoxItem cmbItem in cmb.Items) { if (Enum.Equals((cmbItem.Content as EnumComboBoxItem).Value, val)) { cmb.SelectedItem = cmbItem; break; } } } } else if (val == null) { cmb.Items.Clear(); } }
internal FlagEnumComboBoxItem(FlagEnumComboBox parent, Enum value, Enum[] affectedFlags) { m_Parent = parent; m_Parent.ValueChanged += OnValueChanged; m_Value = value; m_AffectedFlags = affectedFlags; if (m_AffectedFlags.Length > 1) { Type = EnumItemType_e.Combined; } else if (m_AffectedFlags.Length == 0) { Type = EnumItemType_e.None; } else { Type = EnumItemType_e.Default; } Title = EnumControlHelper.GetTitle(m_Value); Description = EnumControlHelper.GetDescription(m_Value); }