Textbox Binding with StringFormat={}{0:N2} without showing zeros

Imilio 41 Reputation points
2022-02-10T21:54:10.553+00:00

Hi, I am binding an object to a TextBox with the following XAML:

<TextBox x:Name="Amount" Text="{Binding Path=Amount, StringFormat={}{0:N2},  UpdateSourceTrigger=PropertyChanged}" />

When I open the window the Text property is set to 0.00. I have several of these TextBoxes, which makes it tedious to delete every value before entering a new one.
Is there a neat way to keep the format and delete the zeros?

Developer technologies | Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-02-10T22:37:55.723+00:00

    If only 0 must be displayed without decimals, then try these formats: StringFormat={}{0:0.00;-0.00;0}.

    Maybe StringFormat={}{0:0.##} is suitable too.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.