Chase
Chase

Reputation: 23

How to add a comma to a custom DateTime StringFormat in WPF

I have a date and time being displayed in a textblock. It currently displays "Jun. 21 2013 10:30 AM" with this code

<TextBlock
    Style="{StaticResource infoTextBlockStyle}"
    Grid.Row="0"
    Grid.Column="3"
    Text="{Binding SecureMessage.SentTime, Mode=OneWay, StringFormat={}{0:MMM. dd yyyy   h:mm:ss tt}}" />

I want it to display with a comma after the day of the month like this: "Jun. 21, 2013 10:30 AM"

Simply adding a comma after the "dd" generates an error where the trailing format strings cannot be recognized. Is there a way to add a comma to this custom StringFormat?

Upvotes: 0

Views: 1446

Answers (1)

LPL
LPL

Reputation: 17083

Wrap format string in single quotes

Text="{Binding StringFormat='{}{0:MMM. dd, yyyy   h:mm:ss tt}'}"

Upvotes: 2

Related Questions