TimeSpan 的 MultiBinding StringFormat [英] MultiBinding StringFormat of TimeSpan
问题描述
我这辈子都无法让它发挥作用.我需要从文本块中的一对时间跨度对象中显示 hh:mm ,但它不起作用.这是我目前所拥有的:
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>
如果我将字符串格式设置为 hust "hh" 那么我只需要几个小时,所以我想我可以用 4 块来构建它,但这感觉不对.任何帮助表示赞赏.
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.
推荐答案
在格式字符串中使用 hh':'mm 似乎有效:
Using hh':'mm in the format string seems to work:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0:hh':'mm} to {1:hh':'mm}">
<Binding Path="StartTime"/>
<Binding Path="EndTime"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
此外,这只适用于 .NET 4
Also, this only works in .NET 4
这篇关于TimeSpan 的 MultiBinding StringFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!