[英]Multi-line string in PropertyGrid (Extended WPF toolkit) without xaml?
扩展的WPF工具包专家,
我正在尝试设置一个字符串属性以接受PropertyGrid控件中的多行。 我不想使用任何xaml来定义编辑模板。 我见过人们通过使用一些属性来使用WinForms PropertyGrid来做这件事。
将属性添加到绑定对象更容易。
有没有人这样做过?
谢谢!
根据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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.