2

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>

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.

Duncan
  • 23
  • 1
  • 3
  • 1
    Possible duplicate of http://stackoverflow.com/questions/4563081/how-to-format-timespan-in-xaml (...) – Bruno Jun 30 '11 at 16:57
  • No, I can format one item fine. This has to do with MultiBinding, which is not working. In fact, I am formatting with the StringFormat (hh\\:mm) already in that post. – Duncan Jun 30 '11 at 17:33
  • duplicate: http://stackoverflow.com/a/33278055/187650 – juFo Oct 22 '15 at 09:46

1 Answers1

9

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>

Also, this only works in .NET 4

sellmeadog
  • 7,437
  • 1
  • 31
  • 45