TimeSpan 的多重绑定 StringFormat
我一辈子都无法让它发挥作用。我需要在文本块中显示一对时间跨度对象的 hh:mm,但它不起作用。这就是我到目前为止所拥有的:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0:hh\\:mm} to {1:hh\\:mm}">
<Binding Path="StartTime"/>
<Binding Path="EndTime"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
文本块显示为空白。我还尝试了以下方法,得到了相同的结果:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0} to {1}">
<Binding Path="StartTime" StringFormat="hh\\:mm"/>
<Binding Path="EndTime" StringFormat="hh\\:mm"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
如果我的字符串格式为 hust“hh”,那么我只能得到小时数,所以我想我可以用 4 块构建它,但这感觉不对。任何帮助表示赞赏。
I cannot for the life of me get this to work. I need to display hh:mm from a pair of timespan objects in a textblock and it is just not working. This is what I have so far:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0:hh\\:mm} to {1:hh\\:mm}">
<Binding Path="StartTime"/>
<Binding Path="EndTime"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
The text block shows up blank. I've also tried the following with the same results:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0} to {1}">
<Binding Path="StartTime" StringFormat="hh\\:mm"/>
<Binding Path="EndTime" StringFormat="hh\\:mm"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
If I have the string format as hust "hh" then I get just the hours, so I suppose I could build it out of 4 pieces but that just does not feel right. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在格式字符串中使用 hh':'mm 似乎有效:
此外,这只适用于 .NET 4
Using hh':'mm in the format string seems to work:
Also, this only works in .NET 4