This project has moved and is read-only. For the latest updates, please go here.

Property Grid DoubleUpDown

Oct 5, 2011 at 6:22 PM

How to set a property double in the property grid, have incremental 0.10? And if possible have the StringFormat N2?

Thanks, that would be useful to me in this situation:



        public double HeightBarCode
                return Convert.ToDouble(String.Format("{0:N2}", CmPixelLengthConverter.PixelToCm(height)));

                height = CmPixelLengthConverter.CmToPixel(value);



Oct 5, 2011 at 6:31 PM

Using the latest source code you can do this:

<extToolkit:PropertyGrid x:Name="_pg">
          <extToolkit:EditorDefinition TargetType="{x:Type sys:Double}">
                          <extToolkit:DoubleUpDown BorderThickness="0" FormatString="N2" Increment="0.10" Value="{Binding Value}" />
Oct 5, 2011 at 6:40 PM

Thank you, there is a prevision a new release version?

Oct 5, 2011 at 6:41 PM

I am targeting the December time frame for the next release.

Oct 5, 2011 at 6:57 PM

Thanks again and one more thing .. To use multiline string editor in PropertyGrid, I must also create an EditorDefinition? Is there a similar way there:

	[Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]


	[Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]


Oct 5, 2011 at 7:07 PM

What type of Property are you trying to add the editor?  Do you want to use a MultiLineTextEditor, or the PrimitiveTypeCollectionEditor?  If you want to use the MutliLineTextEditor then you have a couple of options.

  1. Create an EditorDefinition
  2. Use an the TypeEditor attribute

If you want option 2 you will need to first create a custom editor that implements the ITypeEditor interface.  Here is an example:

    public class MyCustomEditor : ITypeEditor
        public FrameworkElement ResolveEditor(PropertyItem propertyItem)
            TextBox editor = new TextBox();
            Binding binding = new Binding("Value"); //bind to the Value property of the PropertyItem instance
            binding.Source = propertyItem;
            binding.Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay;
            BindingOperations.SetBinding(editor, TextBox.TextProperty, binding);
            return editor;

Then you can use the attribute as folllows:

        private TimeSpan _timeSpan;
        public TimeSpan TimeSpan
            get { return _timeSpan; }
            set { _timeSpan = value; }

If you don't require an attribute, it may be easier to just declare an EditorDefinition in XAML.