为什么 XAML 上的 TimeSpan 具有不同的字符串格式?
我要疯了。有人可以解释一下为什么这些格式化相同内容的字符串格式如此不同吗?
<DataGridTextColumn Header="Max Time" IsReadOnly="True" Binding="{Binding MaxTime, StringFormat=hh\\:mm\\:ss, TargetNullValue=---}">
<DataGridTextColumn Header="Min Time" IsReadOnly="True">
<DataGridTextColumn.Binding>
<Binding Path="MinTime" StringFormat="{}{0:hh':'mm':'ss}" TargetNullValue=" --- "/>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
当然,其中一个对另一个不起作用。
编辑:我使用 WPF 的次数越多,我就越觉得它不是一个足够成熟的产品。
I'm going crazy. Can someone explain me why these string formats formatting the same thing are so different?
<DataGridTextColumn Header="Max Time" IsReadOnly="True" Binding="{Binding MaxTime, StringFormat=hh\\:mm\\:ss, TargetNullValue=---}">
<DataGridTextColumn Header="Min Time" IsReadOnly="True">
<DataGridTextColumn.Binding>
<Binding Path="MinTime" StringFormat="{}{0:hh':'mm':'ss}" TargetNullValue=" --- "/>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
Of course each one do not work on the other.
EDIT: The more I work with WPF the more I feel it's not a mature enought product.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是格式化
TimeSpan
的专家,因此我无法确切地告诉您为什么它们会产生相同的结果,但您可以在这里阅读相关内容:自定义 TimeSpan 格式字符串它们的工作方式相同,只是您应该在双引号内使用一个反斜杠。以下
结果为
hh\\\\:mm\\\\:ss
。因此,您应该编写以下两个
Bindings
应该产生相同的结果,以下两个也应该如此
I'm no expert in formatting
TimeSpan
so I can't tell you exactly why they produce the same result but you can read up about it here: Custom TimeSpan Format StringsThey do work the same way, the thing is just that you should use one backslash within the double quotes. The following
comes out to
hh\\\\:mm\\\\:ss
. So instead you should writeThe following two
Bindings
should produce the same resultAnd so should the following two