[英]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.