How to format TimeSpan in XAML

后端 未结 9 2503
一生所求
一生所求 2020-11-30 00:43

I am trying to format a textblock which is bound to a TimeSpan property. It works if the property is of type DateTime but it fails if it is a

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 01:42

    In .NET 3.5 you could use a MultiBinding instead

    
        
            
                
                
            
        
    
    

    Update
    To answer the comments.

    To make sure you output 2 digits even if hours or minutes is 0-9 you can use {0:00} instead of {0}. This will make sure the output for the time 12:01 is 12:01 instead of 12:1.
    If you want to output 01:01 as 1:01 use StringFormat="{}{0}:{1:00}"

    And Conditional formatting can be used to remove the negative sign for minutes. Instead of {1:00} we can use {1:00;00}

    
        
            
                
                
            
        
    
    

提交回复
热议问题