我已通过DataContext将我的Amount Label的内容属性绑定到十进制属性。我正在尝试应用stringformat但看不到任何效果。 StringFormat 功能是否适用于Label控件?请告诉我这项功能适用于哪些控件。 BTW以下是我想要应用货币格式的标签控制代码
<Label Grid.Column="2" Content="{Binding Path=Amount, StringFormat={}{0:C}}" Height="23" HorizontalAlignment="Left" Margin="100,10,0,0" Name="tb" VerticalAlignment="Bottom" Width="120" />
答案 0 :(得分:29)
StringFormat
适用于string类型的属性(当您绑定的对象被转换为字符串时,将应用字符串格式)。 Content
属性的类型为Object
。
您可以在标签内放置TextBlock以达到预期效果:
<Label Grid.Column="2" Height="23" HorizontalAlignment="Left" Margin="100,10,0,0" Name="tb" VerticalAlignment="Bottom" Width="120">
<TextBlock Text="{Binding Path=Amount, StringFormat={}{0:C}}"/>
</Label>
答案 1 :(得分:28)
尝试ContentStringFormat
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/866f7934-8b10-4872-b306-122674fad5fa/
<Label Content=”{Binding Amount}” ContentStringFormat=”C” />