0

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?

1
  • 1
    I'm no expert, but shouldn't you just escape the comma? (i.e. instead of dd, put dd\,) Commented Jun 21, 2013 at 16:13

1 Answer 1

2

Wrap format string in single quotes

Text="{Binding StringFormat='{}{0:MMM. dd, yyyy   h:mm:ss tt}'}"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! This worked. Escaping the comma as Garrett mentioned above also worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.