我目前正在尝试将WPF TextBlock多重绑定到TimeSpan属性。
以下工作:
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Center"
Text="{Binding Path=ImportOperationRuntime, StringFormat='hh\:mm\:ss'}" />
不幸的是,使用MultiBinding会"破坏"StringFormat并在旁边显示毫秒(尽管通过StringFormat隐藏)。以下不起作用:
<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>
在实际的MultiBinding中使用相同的StringFormats时不起作用(例如:<MultiBinding StringFormat="Total runtime: {0:hh\:mm\:ss}">
)。
我应该如何构建StringFormat?
<MultiBinding StringFormat="Total runtime: {0:hh:mm:ss}">
<Binding Path="ImportOperationRuntime"/>
</MultiBinding>
通常在代码隐藏中,使用双反斜杠\
进行转义。xaml中的情况并非如此。一个就足够了。