扩展的WPF工具包专家,
我试图在PropertyGrid控件中设置一个字符串属性来接受多行。我不想使用任何xaml来定义编辑模板。我见过人们通过使用一些属性来使用WinForms PropertyGrid来做这件事。
将属性添加到绑定对象更容易。
以前有人这样做过吗?
谢谢!
答案 0 :(得分:2)
根据WPF工具包文档,您的自定义编辑控件必须实现ITypeEditor。
示例属性
[Editor(typeof(MultilineTextBoxEditor), typeof(MultilineTextBoxEditor))]
public override string Caption
{
get
{
return caption;
}
set
{
caption = value;
OnPropertyChanged("Caption");
}
}
属性类
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;
}
}