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.

43 lines
1.3 KiB

using System;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class ItemsSourceAttributeEditor : TypeEditor<System.Windows.Controls.ComboBox>
{
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();
}
}
}