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

Autogenerated PropertyGrid : How to change formating of default Editors

Oct 20, 2014 at 1:37 PM
Edited Oct 20, 2014 at 1:39 PM
Hello,

I have multiple PropertyGrid with AutoGenerateProperties="True" in my application.
These PropertyGrid are used to display/input a large number of different objects. Some of their properties need customs editors and some uses the default editors. This is specified in the object class using custom attributes.

My problem is : I must change the way number (Double, Float) are displayed, converted.
For example :
90.5 -> d:90.5
90,5 -> d:90.5 (note the use of ','instead of '.')

How can i specify CultureInfo or FormatString on a DoubleUpDownEditor ? I don't want to use a custom editor for this.
Is there another way ?

Any input is welcome.
Oct 20, 2014 at 5:15 PM
Hi,

In The "Plus" edition of the PropertyGrid, you can customize a DoubleUpDownEditor with properties. Something like :
 <xctk:PropertyGrid Name="_propertyGrid">
         <xctk:PropertyGrid.EditorDefinitions>
            <xctk:EditorDoubleUpDownDefinition TargetProperties="{x:Type sys:Double}"
                                               CultureInfo="fr-FR" />
         </xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>
and the "." will be replaced by "," for every Double in the PropertyGrid. You can modify the CultureInfo or the FormatString.

In the Community edition, you have to define a new DataTemplate for DoubleUpDowns :
 <xctk:PropertyGrid Name="_propertyGrid">
         <xctk:PropertyGrid.EditorDefinitions>
            <xctk:EditorTemplateDefinition TargetProperties="{x:Type sys:Double}">
               <xctk:EditorTemplateDefinition.EditingTemplate>
                  <DataTemplate>
                     <xctk:DoubleUpDown Value="{Binding Value}"
                                        CultureInfo="fr-FR" />
                  </DataTemplate>
               </xctk:EditorTemplateDefinition.EditingTemplate>
            </xctk:EditorTemplateDefinition>
         </xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>
Oct 21, 2014 at 8:11 AM
Edited Oct 21, 2014 at 8:11 AM
Many thanks,

I read about EditorTemplateDefinition but didn't understand it was possible to re-use the DoubleUpDown in the template definnition.
The CultureInfo en-US will parse "." but not "," though (and the opposite for fr-FR) .
I will try something with FormaString.

I am on a good track now thanks to you.