WPF Xaml 的 StringFormat 功能是否适用于 Label.Content?
我已通过 DataContext 将金额标签的内容属性绑定到小数属性。我正在尝试应用字符串格式但没有看到效果。 StringFormat 功能是否适用于标签控件?请告诉我此功能适用于哪些控件。顺便说一句,以下是我要为其应用货币格式的标签控件的代码
<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" />
I have bind my Amount Label's Content Property to a decimal property via DataContext. I am trying to apply stringformat but see no effect. Does StringFormat feature work on Label controls ?? Please tell me on which controls does this feature work. BTW following is the code for the Label Control for whom i want to apply the currency formatting
<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" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
StringFormat
适用于字符串类型的属性(当您绑定的对象转换为字符串时,将应用字符串格式)。Content
属性的类型为Object
。您可以在标签内放置一个 TextBlock 以达到所需的效果:
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). TheContent
property is of typeObject
.You can place a TextBlock inside your label to achieve the desired effect:
尝试
ContentStringFormat
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/866f7934-8b10-4872-b306-122674fad5fa/
Try
ContentStringFormat
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/866f7934-8b10-4872-b306-122674fad5fa/