JuHwon
JuHwon

Reputation: 2063

Label % suffix in binding

I found something like this: How to set WPF string format as percent wihout multiplying by 100?

I just want to have a '%' sign suffix after my number. my code looks like this

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

I already tried this one too

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

in both cases I don't see any changes like I don't have any stringformat.

Upvotes: 4

Views: 1288

Answers (2)

Lukazoid
Lukazoid

Reputation: 19416

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

To get this to work in a label, use ContentStringFormat. If you were to use a TextBlock, you could use the StringFormat provided by Binding.

Upvotes: 3

nemesv
nemesv

Reputation: 139758

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

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

Upvotes: 3

Related Questions