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();
            }
        }
Example #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var enumVal = value as Enum;

            if (enumVal != null)
            {
                var enumType = enumVal.GetType();

                //TODO: this is a simple fix - need to implement more robust solution

                var val  = enumVal.ToString();
                var vals = val.Split(',')
                           .Select(v => (Enum)Enum.Parse(enumType, v.Trim()))
                           .Select(e => EnumControlHelper.GetTitle(e));

                return(string.Join(", ", vals.ToArray()));
            }
            else
            {
                return("");
            }
        }
Example #3
0
            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);
            }