All the controls missing in WPF. Over 1 million downloads.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows.Controls;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class EnumComboBoxEditor : TypeEditor
{
protected override void Initialize()
{
Editor = new ComboBox();
ValueProperty = ComboBox.SelectedItemProperty;
}
public override void Attach(PropertyItem propertyItem)
{
SetItemsSource(propertyItem);
base.Attach(propertyItem);
}
private void SetItemsSource(PropertyItem propertyItem)
{
(Editor as ComboBox).ItemsSource = GetValues(propertyItem.PropertyType);
}
private static object[] GetValues(Type enumType)
{
List<object> values = new List<object>();
var fields = enumType.GetFields().Where(x => x.IsLiteral);
foreach (FieldInfo field in fields)
{
values.Add(field.GetValue(enumType));
}
return values.ToArray();
}
}
}