开发者

How to format a Label to have a Display Format String?

开发者 https://www.devze.com 2023-02-16 07:17 出处:网络
I have a Label: <Label Name=\"lblBilledDate\" Content=\"{Binding Path=BilledDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}\">

I have a Label:

<Label Name="lblBilledDate"
       Content="{Binding Path=BilledDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
</Label>

It is bound to a DateTime value.

How 开发者_如何学Ccan i change the label to display the value to this: DisplayFormatString="dd MMM yyyy"

Currently the Label just dispalys: 1/1/2010

I need it to dispaly: 1 Jan 2010


Use the ContentStringFormat attribute.

<Label x:Name="SomeLabel"
       Content="{Binding BilledDate}"
       ContentStringFormat="dd MMM yyyy" />

This is because Label inherits from ContentControl. Any ContentControl contains the ContentStringFormat attribute. Additionally, ItemsControl has ItemStringFormat and BindingBase has StringFormat.


What about this one?

<Label name="lblSomeLabel">
    <Binding Path="Date" StringFormat="{}{0:dd MMM yyyyy}"/>
</Label>
0

精彩评论

暂无评论...
验证码 换一张
取 消