Pages

Monday, 18 August 2014

String Formatting for TimeSpan

By default a TimeSpan is formatted like this hh:mm:ss

I wanted to format a TimeSpan in XAML and differentiate it from a normal time format, something like this 02h30m

After a bit of fiddling with curly brackets and back slashes I settled on:

"{Binding Path=Duration, StringFormat={}{0:hh}h{0:mm}m}"