【发布时间】:2017-07-19 04:38:46
【问题描述】:
我有一个 WPF 应用程序。我有一些标签和一些绑定到一些公共属性的数据网格。其中一些属性是数值。
在数据网格中,我一直在使用下面的行来确保值只显示两位小数,这很有效。但是,当我为标签使用下面的同一行时,它似乎对显示没有影响,因为数字显示到小数点后 9 位左右。我不明白为什么它适用于数据网格而不适用于标签?
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"/>
更新代码
<Label Grid.Row="3" Grid.Column="1"
Content="{Binding Obs.Tstat}" ContentStringFormat="{}{0:0.#}}"
HorizontalAlignment="Center" Foreground="{StaticResource brushLinFont}"
FontSize="13" FontWeight="Bold"/>
【问题讨论】: