Extended WPF toolkit experts,
I'm trying to set a string property to accept multi-line in the PropertyGrid control. I don't want to use any xaml to define an editing template. I have seen people do this with WinForms PropertyGrid through the use of some attributes.
It's easier me for to add attributes to the bound object.
Has anyone done this before?
Thanks!
According to WPF toolkit docs, your custom editing control must implement the ITypeEditor.
Example Property
[Editor(typeof(MultilineTextBoxEditor), typeof(MultilineTextBoxEditor))]
public override string Caption
{
get
{
return caption;
}
set
{
caption = value;
OnPropertyChanged("Caption");
}
}
Attribute Class
public class MultilineTextBoxEditor : Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor
{
public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem)
{
System.Windows.Controls.TextBox textBox = new
System.Windows.Controls.TextBox();
textBox.AcceptsReturn = true;
//create the binding from the bound property item to the editor
var _binding = new Binding("Value"); //bind to the Value property of the PropertyItem
_binding.Source = propertyItem;
_binding.ValidatesOnExceptions = true;
_binding.ValidatesOnDataErrors = true;
_binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
BindingOperations.SetBinding(textBox, System.Windows.Controls.TextBox.TextProperty, _binding);
return textBox;
}
}