MultiBinding StringFormat TimeSpan

I can't make me work for life. I need to display hh: mm from a pair of timespan objects in a text block, and it just doesn't work. 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 is displayed blank. I 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 a string format like hust "hh", then I only get the clock, so I suppose I could build it from 4 pieces, but that just isn’t. Any help is appreciated.

+1
source share
1 answer

Using hh ':' mm in a format string:

 <TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}From {0:hh':'mm} to {1:hh':'mm}"> <Binding Path="StartTime"/> <Binding Path="EndTime"/> </MultiBinding> </TextBlock.Text> </TextBlock> 

Also, this only works in .NET 4

+8
source

All Articles