Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set WPF string format as percent wihout multiplying by 100?

I have a textbox bound to a property in an object. I have setup the string format to be p0.

However, when I enter 12 for example it is formatted as 1200% (multiplies by 100 and add % sign)

How can i set the stringformat so that for exampe 20 is formatted as 20% ?

My current control is :

<TextBox Text="{Binding Path=MyCase, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, StringFormat=p0}"/>

how t change the string format so that the format for 7 is 7% not 700% ?

like image 641
Emad Gabriel Avatar asked Aug 15 '09 22:08

Emad Gabriel


2 Answers

"{Binding Path=Percentage, StringFormat={}{0}%}"
like image 96
Thomas Levesque Avatar answered Oct 29 '22 20:10

Thomas Levesque


Another solution is to wrap the % in single quotes, and put it inside the curley brackets:

<TextBlock Text="{Binding Percentage, StringFormat={}{0:#0.00'%'}}"/>
like image 27
Contango Avatar answered Oct 29 '22 20:10

Contango