using System; using Microsoft.Windows.Controls.PropertyGrid.Attributes; namespace Microsoft.Windows.Controls.PropertyGrid.Editors { public class ItemsSourceAttributeEditor : TypeEditor { private readonly ItemsSourceAttribute _attribute; public ItemsSourceAttributeEditor(ItemsSourceAttribute attribute) { _attribute = attribute; } protected override void SetValueDependencyProperty() { ValueProperty = System.Windows.Controls.ComboBox.SelectedValueProperty; } protected override void ResolveValueBinding(PropertyItem propertyItem) { SetItemsSource(); base.ResolveValueBinding(propertyItem); } protected override void SetControlProperties() { Editor.DisplayMemberPath = "DisplayName"; Editor.SelectedValuePath = "Value"; } private void SetItemsSource() { Editor.ItemsSource = CreateItemsSource(); } private System.Collections.IEnumerable CreateItemsSource() { var instance = Activator.CreateInstance(_attribute.Type); return (instance as IItemsSource).GetValues(); } } }