How to use TimeSpan string format in code in Xamarin.Forms?

Viewed 6158

I am using a Label in Xamarin.Forms in code like so:

var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("Time", stringFormat: "{}{0:hh\\:mm}", mode: BindingMode.TwoWay, source: this));

But this returns the error:

System.FormatException: Input string was not in a correct format.

But this works in Xaml:

 <Label Text="{Binding StartTime, StringFormat='{}{0:hh\\:mm}'}}"/>

How do I use string format on a binding for TimeSpan in Xamarin.Forms?

2 Answers

StringFormat='{}{0:hh\\:mm\\:ss}'

Related