c# - WPF formatting labels with StringFormat -


i have wpf application. have labels , datagrids bound public properties. of these properties numerical values.

in datagrids have been using line below ensure values display 2 decimal places, works. when use same line below label appears have no effect on display number shows 9 decimal places. don't understand why works datagrid not label?

stringformat={}{0:0.##}    <label grid.row="3" grid.column="1"        content="{binding obs.tstat, stringformat={}{0:0.#}}"         horizontalalignment="center" foreground="{staticresource brushlinfont}"         fontsize="13" fontweight="bold"/> 

updated code

 <label grid.row="3" grid.column="1"         content="{binding obs.tstat}" contentstringformat="{}{0:0.#}}"          horizontalalignment="center" foreground="{staticresource brushlinfont}"          fontsize="13" fontweight="bold"/> 

for label need use contentstringformat:

<label content="{binding obs.tstat}" contentstringformat="{}{0:0.##}"/> 

reason:

label's content property of type object , stringformat used when binding property of type string.

if try code textblock's text property work fine stringformat because text property of type string.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -