TimeSpanConverter.cs 872 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Data;
  8. namespace MECF.Framework.UI.Core.Converters
  9. {
  10. public class TimeSpanConverter : IValueConverter
  11. {
  12. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  13. {
  14. if (value == null || !(value is TimeSpan))
  15. {
  16. return null;
  17. }
  18. TimeSpan ts = (TimeSpan)value;
  19. if (ts.Days > 0)
  20. return $"{ts.Days}d {ts.Hours}h";
  21. else return $"{ts.Hours}h {ts.Minutes}m";
  22. }
  23. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  24. {
  25. throw new NotImplementedException();
  26. }
  27. }
  28. }