1234567891011121314151617181920212223242526 |
- using System;
- namespace InABox.WPF;
- public class TimeSpanToStringConverter : UtilityConverter<TimeSpan,String>
- {
- public TimeSpanToStringConverter(string? format)
- {
- Format = format ?? "HH:mm";
- }
- public string Format { get; set; }
-
- public override string Convert(TimeSpan value)
- {
- var result = string.IsNullOrWhiteSpace(Format) || string.Equals(Format, "hh:mm")|| string.Equals(Format, "HH:mm")
- ? Math.Truncate(value.TotalHours).ToString("#00") + ":" + value.Minutes.ToString("D2")
- : string.Format("{0:" + Format.Replace(":", "\\:") + "}", value);
- return result;
- }
- public override TimeSpan Deconvert(string value)
- {
- return base.Deconvert(value);
- }
- }
|