我有一个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"/>
Obs.Tstat
的边界值是多少? - Rohit Vats"{}{0:0.#}"
而不是"{}{0:0.#}}"
。请删除最后一个多余的花括号。 - Rohit Vats