Does StringFormat feature of WPF Xaml work on Label.Content?

末鹿安然 提交于 2019-11-27 23:28:16

StringFormat works on properties of type string (when the object you are binding to is being converted to a string the string format is applied). The Content property is of type Object.

You can place a TextBlock inside your label to achieve the desired effect:

<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>
JamesM

Try ContentStringFormat

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/866f7934-8b10-4872-b306-122674fad5fa/

<Label Content=”{Binding Amount}” ContentStringFormat=”C” /> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!