4

我发现了这样的事情: 如何将 WPF 字符串格式设置为不乘以 100 的百分比?

我只想在我的号码后面加一个“%”符号后缀。我的代码看起来像这样

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

这个我也试过了

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

在这两种情况下,我都没有看到任何变化,比如我没有任何字符串格式。

4

2 回答 2

3

如果Label您需要使用ContentStringFormat属性

<Label Content="{Binding Path=ReportGridViewModel.FillingDegree}" 
       ContentStringFormat="P" />
于 2013-01-23T13:10:25.383 回答
3

仅当目标属性为 类型时才应用StringFormata的属性。在 a中,目标属性是 type ,因此不受尊重。BindingStringLabelContentObjectStringFormat

要使其在标签中起作用,请使用ContentStringFormat. 如果您要使用 a TextBlock,则可以使用StringFormat提供的 by Binding

于 2013-01-23T13:23:15.210 回答