Hi,
I want to format the numbers entered in xamdatagrid to have percentage sign(ex : when user enters 30 it should be displayed as 30%). I created a style for xamtextEditor and used that in grid. The percent sign is displayed but if user enters 3 it is displayed as 300%. Please help .Below is the style:
<Style x:Key="PercentStyle" TargetType="{x:Type igEditors:XamTextEditor}">
<Style.Setters>
<Setter Property="ValueType" Value="{x:Type System:Decimal}"/>
<Setter Property="Format" Value="###.##%"/>
<Setter Property="InvalidValueBehavior" Value="RetainValue" />
<Setter Property="HorizontalContentAlignment" Value="Right"/>
</Style.Setters>
</Style>
Hello,
Using this setting, the value editor will display the value multiplied by 100. That is why when the value is 3, 300% is presented. One options is to create a IValueConverter for this and apply it to the Converter property of the field. Another way would be to apply this converter to the ValueToDisplayTextConverter property of the editor.
I was going through this thread. I have a similar question, where i want to use the percentage formatter for specific fields. Is there a way to set the formatter for the specific fields from the code behind?
Regards,
Sagar
Hi Stefan,
Thanks for the reply.
I tried inserting your code in the Grid - Initialized event. It did not work in my case. is that what you meant ?
Hello Sagar,
You should put the code in the MainWindow's constructor before the call of the InitializeComponent method like this:
public partial class MainWindow : Window { public MainWindow() { CultureInfo ci = (CultureInfo)Thread.CurrentThread.CurrentUICulture.Clone(); ci.NumberFormat.CurrencySymbol = String.Empty; Thread.CurrentThread.CurrentUICulture = ci; Thread.CurrentThread.CurrentCulture = ci; InitializeComponent(); } }
Is there anyway to adjust the editor rather then the entire Culture? I have other fields in my grid which I want to keep the $ symbol for.
Hello Nick,
You can set the Editor's Mask in order to change the currency symbol. You can set it like this:
Mask="@nnn,nnn,nn"
Also, here you can see the available masks:
http://help.infragistics.com/Help/Doc/WPF/2016.1/CLR4.0/html/xamInputs_Masks.html
Hope this helps you.
Thanks very much!