Property Grid DoubleUpDown

Oct 5, 2011 at 5: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:

 

 

        [Category("Tamanho")]
        [DisplayName("Altura")]
        public double HeightBarCode
        {
            get
            {
                return Convert.ToDouble(String.Format("{0:N2}", CmPixelLengthConverter.PixelToCm(height)));
            }
            set
            {

                height = CmPixelLengthConverter.CmToPixel(value);
                OnPropertyChanged("HeightBarCode");
            }
        }

 

 

Oct 5, 2011 at 5:31 PM

Using the latest source code you can do this:

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

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

Oct 5, 2011 at 5:41 PM

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

Oct 5, 2011 at 5: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))]
        [Category("Text")]
        [DisplayName("Before-Text")]

or

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

?

Oct 5, 2011 at 6: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;
        [TypeEditor(typeof(MyCustomEditor))]
        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.