I am binding an object to a XamDataPresenter and one of the properties is of decimal type. At run-time, it displays with commas separating the thousands and a dollar in front of the value. How do I stop this?
I tried explicitly defining the field, but this didn't help:
<igData:XamDataPresenter Name="dpMyData" DataSource="{Binding}"> <igData:XamDataPresenter.FieldLayoutSettings> <igData:FieldLayoutSettings AutoGenerateFields="False" /> </igData:XamDataPresenter.FieldLayoutSettings> <igData:XamDataPresenter.FieldLayouts> <igData:FieldLayout> <igData:FieldLayout.Fields> <igData:Field Name="MyField" DataType="{x:Type sys:Decimal}" /> </igData:FieldLayout.Fields> </igData:FieldLayout> </igData:XamDataPresenter.FieldLayouts></igData:XamDataPresenter>
Hello,
This is because the default XamEditor for fields of type decimal is XamCurrencyEditor and this is the reason of the currency symbol and the commas.
To void that you have to register new XamEditor for this field. Here is a thread in the forum that I answered a similar question.
http://forums.infragistics.com/forums/p/20591/74287.aspx#74287
Hope this helps
Alex.
Hi Alex,
Thanks for your help here. I had a reply from Infragistics Developer Support, which is probably along the lines of your other thread where you answered a similar question. They said:
The reason you are getting the currency symbol in your decimal field is because the default editor for a decimal field in the XamDataGrid is the XamCurrencyEditor. However, you can change this by setting the Field's EditorType property to use the XamNumericEditor. You can use the following xaml code snippet:
<igData:XamDataGrid Margin="31,12,56,43" Name="xamDataPresenter1" > <igData:XamDataGrid.FieldLayoutSettings> <igData:FieldLayoutSettings AutoGenerateFields="False" /> </igData:XamDataGrid.FieldLayoutSettings> <igData:XamDataGrid.FieldLayouts> <igData:FieldLayout> <igData:FieldLayout.Fields> <igData:Field Name="MyField"> <igData:Field.Settings> <igData:FieldSettings EditorType="{x:Type igEditors:XamNumericEditor}" EditAsType="{x:Type sys:Double}" /> </igData:Field.Settings> </igData:Field> <igData:Field Name="Name" /> </igData:FieldLayout.Fields> </igData:FieldLayout> </igData:XamDataGrid.FieldLayouts> </igData:XamDataGrid>
For more Information you may refer the following online help article:
<http://help.infragistics.com/Help/NetAdvantage/WPF/2008.2/CLR3.X/html/xamData_Default_Editor_Types_for_Different_Data_Types.html>
Yes this is almost the same way to do that and it is up to you to choose between the two ways.
If you want, you can change the EditorStyle and EditAsType like they have shown, but :
1) you will change the data type of the field
2) you will have to do this for every field you want to do this.
By registering a different XamEditor for a ValueType you will not change the data type (from decimal to double) and you will not have to repeat changing the EditorType for every field.
Alex
Thanks Alex,
I ended up going with the option provided by Developer Support for my case because there were actually some cases where I wanted a decimal to be represented by a XamCurrencyEditor.
Just another quick question for you though you may know the answer to in your infinite wisdom :) ...
In the cases I want it to be represented by a XamCurrencyEditor, how do I change the currency, or even remove the currency sign altogether but still keep it as a XamCurrencyEditor?
Thanks,
Jason
If you specify an explicit Mask then you would not get a currency symbol (unless you include one in the mask). Also, you can use a static method (RegisterDefaultMaskForType) to change the default mask that is used for particular data types.
Alex, thanks for your help. Your solution actually fixed another issue I was having with the dates appearing in en-US format; your solution fixed this so that they now appear in en-GB format.
Andrew, thanks for your help too. I prefer the use of an explicit Mask and tried to apply this to my XamDataGrid via a Style as thus:
<igData:XamDataGrid.Resources> <Style TargetType="{x:Type igEditors:XamCurrencyEditor}"> <Setter Property="Mask" Value="nnnn"/> </Style></igData:XamDataGrid.Resources>
But it doesn't appear to be having any effect. Any idea on this?
I've also got some DateTime properties being bound to my XamDataGrid and would like to modify the Mask for these cells too, so that the date and time are displayed rather than just the date, but only for some of the DateTime properties, not all. Is this possible?
Many thanks,
XtreemX said: But it doesn't appear to be having any effect. Any idea on this?
XtreemX said: I've also got some DateTime properties being bound to my XamDataGrid and would like to modify the Mask for these cells too, so that the date and time are displayed rather than just the date, but only for some of the DateTime properties, not all. Is this possible?
Excellent, thank you. It's all sorted now and works great.
XtreemX said: XamMaskedEditor.RegisterDefaultMaskForType(typeof(XamCurrencyEditor), "{nnnn}");
XamMaskedEditor.RegisterDefaultMaskForType(typeof(XamCurrencyEditor), "{nnnn}");
That method is for specifying the mask to use for a given datatype not editor control type. So you would use the target data type. e.g. XamMaskedEditor.RegisterDefaultMaskForType(typeof(decimal), "{nnnn}");
Ah, yes, I had two Styles set in my XamDataGrid.Resources:
<Style TargetType="{x:Type igData:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Right"/></Style><Style TargetType="{x:Type igEditors:XamCurrencyEditor}"> <Setter Property="Mask" Value="nnnn"/></Style>
I guess the second one wasn't being picked up. However, I have tried setting the second 'Mask' setting programmatically with the following code as this isn't having any effect either:
...and even:
XamMaskedEditor.RegisterDefaultMaskForType(typeof(XamCurrencyEditor), "{XXXX}");
Am I doing anything wrong?
By the way, I was able to get date and time displayed using the method you mentioned with the following code as a child of 'Field':
<igData:Field.Settings> <igData:FieldSettings> <igData:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamDateTimeEditor}"> <Setter Property="Mask" Value="{}{date} {time}" /> </Style> </igData:FieldSettings.EditorStyle> </igData:FieldSettings></igData:Field.Settings>
So, thank you for that. However, I want to avoid having to do this for each currency field as this is a more general requirement.