TextBox changes the value to decimal (EN) when pressing TAB, but I want to leave currency (REAL) field

3

I have a field

 <TextBox x:Name="TbTotalICMS" Style="{StaticResource MeuTextBoxValor}" Text="{Binding Vicms}" />

My Vicms is a decimal. When pressing the TAB key, the value is 1.00 (example) it turns 100. For as it is a decimal in English it takes the comma and exchange by point. I need that by pressing the TAB it continues like this.

    
asked by anonymous 06.08.2018 / 14:37

2 answers

1

I solved this by putting a ConverterCulture!

 <TextBox x:Name="TbTotalICMS" Style="{StaticResource MeuTextBoxValor}" Text="{Binding Vicms,  ConverterCulture='pt-BR'}" />
    
06.08.2018 / 15:15
1

In the event of LostFocus there is always the possibility to convert / force the value to the format we want:

NumberFormatInfo numberFormatInfo = new NumberFormatInfo();

// número de casas decimais
numberFormatInfo.NumberDecimalDigits = 2;
// separador de casas decimais
numberFormatInfo.NumberDecimalSeparator = ",";
// separador de milhares
numberFormatInfo.NumberGroupSeparator = ".";
string value = DoubleValue.ToString("N", numberFormatInfo);
    
06.08.2018 / 15:02