<extToolkit:TokenizedTextBox x:Name="_textBox"
DisplayMemberPath="FullName" //value to display
SearchMemberPath="FirstName" //value to search for when typing
ValueMemberPath="Id" //value to store in text property />
//code behind
_textBox.Text = "1;2;"; //list of object ids
_textBox.ItemsSource = new List<Email>() //use as lookup values
{
new Email() { Id = 1, FirstName = "John", LastName = "Doe", EmailAddress = "john@test.com" },
new Email() { Id = 2, FirstName = "Jane", LastName = "Doe", EmailAddress = "jane@test.com" },
};
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; }
}
<extToolkit:PropertyGrid AutoGenerateProperties="False">
<extToolkit:PropertyGrid.PropertyDefinitions>
<extToolkit:PropertyDefinition Name="FirstName" />
<extToolkit:PropertyDefinition Name="Age" />
</extToolkit:PropertyGrid.PropertyDefinitions>
</extToolkit:PropertyGrid>
This will only show the FirstName and Age properties of the bound object.
[TypeConverter(typeof(ExpandableObjectConverter))]
public Person Admin
{
get { return _admin; }
set { _admin = value; }
}
For now it works with the above syntax.
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().
This example will provide a TextBox editor for any property of type DateTime as well as any property with the defined property names:
<extToolkit:PropertyGrid>
<extToolkit:PropertyGrid.EditorDefinitions>
<extToolkit:EditorDefinition TargetType="{x:Type sys:DateTime}">
<extToolkit:EditorDefinition.Properties>
<sys:String>FirstName</sys:String>
<sys:String>LastName</sys:String>
</extToolkit:EditorDefinition.Properties>
<extToolkit:EditorDefinition.EditorTemplate>
<DataTemplate>
<TextBox Text="{Binding Value}" />
</DataTemplate>
</extToolkit:EditorDefinition.EditorTemplate>
</extToolkit:EditorDefinition>
</extToolkit:PropertyGrid.EditorDefinitions>
</extToolkit:PropertyGrid>
You can also target just a Type or just property names.