我有一个标签:
<Label Name="lblBilledDate"
Content="{Binding Path=BilledDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
</Label>
它绑定(bind)到一个 DateTime
值。
如何更改标签以将值显示为:DisplayFormatString="dd MMM yyyy"
目前标签刚刚显示:2010 年 1 月 1 日
我需要它来显示:2010 年 1 月 1 日
最佳答案
使用 ContentStringFormat
属性。
<Label x:Name="SomeLabel"
Content="{Binding BilledDate}"
ContentStringFormat="dd MMM yyyy" />
这是因为 Label
继承自 ContentControl
。任何 ContentControl
都包含 ContentStringFormat
属性。此外,ItemsControl
有 ItemStringFormat
,BindingBase
有 StringFormat
。
https://stackoverflow.com/questions/5249987/