The syntax is as follows:
public class Person
{
[Description("First Name")]
public string FirstName { get; set; }
[Description("Last Name")]
public string LastName { get; set; }
[ExpandableObject]
public Person Spouse { get; set; }
}
public class MyCustomEditor : ITypeEditor
{
public FrameworkElement ResolveEditor(PropertyItem propertyItem)
{
TextBox editor = new TextBox();
Binding binding = new Binding("Value"); //bind to the Value property of the PropertyItem instance
binding.Source = propertyItem;
binding.Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay;
BindingOperations.SetBinding(editor, TextBox.TextProperty, binding);
return editor;
}
}
Then attribute the property to use the editor on:
private TimeSpan _timeSpan;
[TypeEditor(typeof(MyCustomEditor))]
public TimeSpan TimeSpan
{
get { return _timeSpan; }
set { _timeSpan = value; }
}
public class ColorSource : IItemsSource
{
public IList<object> GetValues()
{
return new List<object>() { Colors.Blue, Colors.Gray, Colors.Green };
}
}
Then decorate your property with the ItemsSource attirbute and specify the Type of source to use:
private Color _color = Colors.Green;
[ItemsSource(typeof(ColorSource))]
public Color Color
{
get { return _color; }
set { _color = value; }
}
When the PropertyGrid loads, the editor for the Color property will be a ComboBox with an ItemsSource of ColorSource.GetValues().