是否可以使用字符串格式string.Format("stuff happened on {0}", date)
,还可以使用日期格式设置日期格式?
我当然可以使用string.Format("stuff {0}", date.ToString("d"))
;但是,当我在这样的XAML绑定中使用StringFormat
时,它将无法飞行:
<TextBlock Text={Binding SomeDate,StringFormat='{}stuff happened on {0}'} />
答案 0 :(得分:1)
使用鲜为人知的optional parts of the format item可以做到这一点。那些是index [,alignment] [:formatString]
中的 alignment 和 formatString 。
所以,我可以使用以下内容回答我的问题:
<TextBlock Text={Binding SomeDate,StringFormat='{}stuff happened on {0,10:d}'} />