我找到了类似这样的东西:How to set WPF string format as percent wihout multiplying by 100?
我只想在我的数字后面有一个'%‘符号后缀。我的代码如下所示
<Label Content="{Binding Path=ReportGridViewModel.FillingDegree, StringFormat=P}" />我也已经试过这个了
<Label Content="{Binding ReportGridViewModel.Cgi, StringFormat={}{0}%}" />在这两种情况下,我都看不到任何变化,比如我没有任何字符串格式。
发布于 2013-01-23 21:23:15
仅当Binding属性的类型为String时,才应用目标的StringFormat属性。在Label中,目标属性Content的类型为Object,因此不考虑StringFormat。
要使其在标签中起作用,请使用ContentStringFormat。如果要使用TextBlock,可以使用Binding提供的StringFormat。
发布于 2013-01-23 21:10:25
对于Label,您需要使用ContentStringFormat属性
<Label Content="{Binding Path=ReportGridViewModel.FillingDegree}"
ContentStringFormat="P" />https://stackoverflow.com/questions/14480429
复制相似问题