Label% affix suffix

I found something like this: How to set WPF string format as a percentage when multiplied by 100?

I just want to have a suffix with the inscription "%" after my number. my code is as follows

<Label Content="{Binding Path=ReportGridViewModel.FillingDegree, StringFormat=P}" /> 

I already tried this too

 <Label Content="{Binding ReportGridViewModel.Cgi, StringFormat={}{0}%}" /> 

In both cases, I do not see any changes, for example, I do not have a string format.

+4
source share
2 answers

The StringFormat property of the Binding object applies only when the target property is of type String . In Label target Content property is of type Object , so StringFormat not respected.

To make it work on a shortcut, use ContentStringFormat . If you must use a TextBlock , you can use the StringFormat provided by Binding .

+3
source

In the case of Label you need to use the ContentStringFormat property

 <Label Content="{Binding Path=ReportGridViewModel.FillingDegree}" ContentStringFormat="P" /> 
+3
source

All Articles