/// <summary> /// Creates the select control. /// </summary> /// <param name="property">The property.</param> /// <param name="options">The options.</param> /// <returns> /// The control. /// </returns> protected virtual FrameworkElement CreateEnumControl( PropertyItem property, PropertyControlFactoryOptions options) { var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType); var values = Enum.GetValues(enumType); var style = property.SelectorStyle; if (style == DataAnnotations.SelectorStyle.Auto) { style = values.Length > options.EnumAsRadioButtonsLimit ? DataAnnotations.SelectorStyle.ComboBox : DataAnnotations.SelectorStyle.RadioButtons; } switch (style) { case DataAnnotations.SelectorStyle.RadioButtons: { var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType }; c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding()); return c; } case DataAnnotations.SelectorStyle.ComboBox: { var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) }; c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding()); return c; } case DataAnnotations.SelectorStyle.ListBox: { var c = new ListBox { ItemsSource = Enum.GetValues(enumType) }; c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding()); return c; } default: return null; } }
/// <summary> /// Creates the enum control. /// </summary> /// <param name="property"> /// The property. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The control. /// </returns> protected FrameworkElement CreateEnumControl(PropertyItem property, PropertyControlFactoryOptions options) { var isRadioButton = true; var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType); var values = Enum.GetValues(enumType); if (values.Length > options.EnumAsRadioButtonsLimit && !property.UseRadioButtons) { isRadioButton = false; } if (isRadioButton) { var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType }; c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding()); return c; } else { var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) }; c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding()); return c; } }