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?
Normally in code behind you use a double backslash
\\
for escaping. This is not the case in xaml. One is enough.