开发者

MultiBinding StringFormat of TimeSpan

开发者 https://www.devze.com 2023-03-16 06:58 出处:网络
I cannot for the life of me get this to work.I need to display hh:mm from a pair of ti开发者_如何学Cmespan objects in a textblock and it is just not working.This is what I have so far:

I cannot for the life of me get this to work. I need to display hh:mm from a pair of ti开发者_如何学Cmespan 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号