【问题标题】:Multi-line string in PropertyGrid (Extended WPF toolkit) without xaml?没有 xaml 的 PropertyGrid(扩展 WPF 工具包)中的多行字符串?
【发布时间】:2018-02-10 19:19:52
【问题描述】:

扩展的 WPF 工具包专家,

我正在尝试在 PropertyGrid 控件中设置一个字符串属性以接受多行。我不想使用任何 xaml 来定义编辑模板。我已经看到人们通过使用某些属性来使用 WinForms PropertyGrid 做到这一点。

为绑定的对象添加属性更容易。

以前有人做过吗?

谢谢!

【问题讨论】:

    标签: c# wpf wpftoolkit propertygrid


    【解决方案1】:

    根据 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;
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 2012-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      相关资源
      最近更新 更多