Textbox masks value from 2 to 4 decimal places in WPF C#

Asked

Viewed 560 times

3

I wish my Textbox had the following "mask" When I put two houses after the comma:

0,00

or when I put three:

0,000

or when I put 4:

0,0000

My code in WPF C# and the following:

 <TextBox  x:Name="ValorProdutoTextBox"  
  Text="{Binding ValorProduto, NotifyOnValidationError=true,
  ValidatesOnExceptions=true,  ConverterCulture='pt-BR'}"
  UpdateSourceTrigger="ValorLostFocus"
   Height="20"
   Width="100" Margin="1" />

The result is always coming as determined by the 'Binding Product' that is in the database (DECIMAL 15.4)

0,0000

  • 1

    You tried to add a StringFormat=N2 in your Binding?

  • @Leandroangelo the N2 only goes two decimal places.

1 answer

2


Follow the example of the code:

<TextBox Text="{Binding Value, StringFormat=N2}" />
<TextBox Text="{Binding Value, StringFormat={}{0:#,#.00}}" />

Original response: Stackoverflow English

Browser other questions tagged

You are not signed in. Login or sign up in order to post.