tags:

views:

20

answers:

1

My label is displaying '7/27/2010' instead of 'July 27, 2010'. Can someone please tell me why my markup code is apparently ignored?

RibbonLabel Content="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='{}{0:MMMM d, yyyy}'}" 

Cheers,
Berryl

+1  A: 

The StringFormat property is only used if the binding is applied to a property of type String. Since Content is of type object, it is not used. Instead of setting the content to the date directly, set it to a TextBlock, and set the Text property of the TextBlock using a StringFormat:

<RibbonLabel>
    <TextBlock Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='{}{0:MMMM d, yyyy}'}"/>
</RibbonLabel>

You could also define a DataTemplate for DateTime and then just set the content to Today:

<Window.Resources>
    <DataTemplate DataType="{x:Type sys:DateTime}">
        <TextBlock Text="{Binding StringFormat='{}{0:MMMM d, yyyy}'}"/>
    </DataTemplate>
</Window.Resources>
...
<RibbonLabel Content="{Binding Source={x:Static sys:DateTime.Today}}">
Quartermeister