【问题标题】:How to add a comma to a custom DateTime StringFormat in WPF如何在 WPF 中将逗号添加到自定义 DateTime StringFormat
【发布时间】:2013-06-21 15:51:43
【问题描述】:

我在文本块中显示了日期和时间。它目前显示“Jun. 21 2013 10:30 AM”,并带有此代码

<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}}" />

我希望它在月份的某一天之后用逗号显示,如下所示:“Jun. 21, 2013 10:30 AM”

只需在“dd”后添加一个逗号,就会产生无法识别尾随格式字符串的错误。有没有办法在这个自定义的 StringFormat 中添加逗号?

【问题讨论】:

  • 我不是专家,但你不应该只是逃避逗号吗? (即,而不是dd, 放入dd\,

标签: wpf datetime-format comma string-formatting format-string


【解决方案1】:

用单引号包裹格式字符串

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

【讨论】:

  • 谢谢!这行得通。上面提到的加勒特转义逗号也有效。
猜你喜欢
  • 1970-01-01
  • 2013-10-17
  • 1970-01-01
  • 2013-03-12
  • 2010-12-15
  • 1970-01-01
  • 1970-01-01
  • 2015-10-17
  • 2010-11-12
相关资源
最近更新 更多