问题描述
目前我想multibind一个WPF TextBlock的一个时间跨度财产
以下工作:
< TextBlock中的HorizontalAlignment =右
VerticalAlignment =中心
文本={绑定路径= ImportOperationRuntime,的StringFormat ='hh\\: mm\\:SS'}/>
不幸的是,使用一个MultiBinding破坏了的StringFormat和旁边显示毫秒(尽管通过的StringFormat隐藏)。下面的人不工作:
< TextBlock的Grid.Column =6VerticalAlignment =中心>
< TextBlock.Text>
< MultiBinding的StringFormat =总运行时间:{0}>
<绑定路径=ImportOperationRuntime的StringFormat =HH:毫米:SS/>
< / MultiBinding>
< /TextBlock.Text>
< / TextBlock的>
< TextBlock的Grid.Column =6VerticalAlignment =中心>
< TextBlock.Text>
< MultiBinding的StringFormat =总运行时间:{0}>
<绑定路径=ImportOperationRuntime的StringFormat =hh\:mm\:SS/>
< / MultiBinding>
< /TextBlock.Text>
< / TextBlock的>
< TextBlock的Grid.Column =6VerticalAlignment =中心>
< TextBlock.Text>
< MultiBinding的StringFormat =总运行时间:{0}>
<绑定路径=ImportOperationRuntime的StringFormat =hh\\:mm\\:SS/>
< / MultiBinding>
< /TextBlock.Text>
< / TextBlock的>
< TextBlock的Grid.Column =6VerticalAlignment =中心>
< TextBlock.Text>
< MultiBinding的StringFormat =总运行时间:{0}>
<绑定路径=ImportOperationRuntime的StringFormat =HH:MM:SS/>
< / MultiBinding>
< /TextBlock.Text>
< / TextBlock的>
和非常相同的StringFormats实际MultiBinding使用时不工作(例如:< MultiBinding的StringFormat =总运行时间:{0:hh\\:mm\\:SS}>
)
$ b。 $ b
我应该如何组织我的StringFormat
< MultiBinding的StringFormat =总运行时间:{0:hh\:mm\:SS}>
<绑定路径=ImportOperationRuntime/>
< / MultiBinding>
通常,在后面的代码使用一个双反斜线 \\
转义。
这不是在XAML的情况。一个就足够了。
I'm currently trying to multibind a WPF TextBlock to a TimeSpan property.
The following works:
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Center"
Text="{Binding Path=ImportOperationRuntime, StringFormat='hh\\:mm\\:ss'}" />
Unfortunately, using a MultiBinding "destroys" the StringFormat and displays the milliseconds alongside (though hidden through the StringFormat). The following ones do not work:
<TextBlock Grid.Column="6" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="Total runtime: {0}">
<Binding Path="ImportOperationRuntime" StringFormat="hh':'mm':'ss" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Column="6" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="Total runtime: {0}">
<Binding Path="ImportOperationRuntime" StringFormat="hh\:mm\:ss" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Column="6" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="Total runtime: {0}">
<Binding Path="ImportOperationRuntime" StringFormat="hh\\:mm\\:ss" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Column="6" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding StringFormat="Total runtime: {0}">
<Binding Path="ImportOperationRuntime" StringFormat="hh:mm:ss" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
And the very same StringFormats when used in the actual MultiBinding do not work (ex: <MultiBinding StringFormat="Total runtime: {0:hh\\:mm\\:ss}">
).
How should I structure my StringFormat?
<MultiBinding StringFormat="Total runtime: {0:hh\:mm\:ss}">
<Binding Path="ImportOperationRuntime"/>
</MultiBinding>
Normally in code behind you use a double backslash \\
for escaping.This is not the case in xaml. One is enough.
这篇关于格式化MultiBinding时间跨度隐藏毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!