简体   繁体   中英

Multi-line string in PropertyGrid (Extended WPF toolkit) without xaml?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM