Microscopic Traffic Simulator
FromTimeSpanToHoursString.cs
Go to the documentation of this file.
1 using System;
2 using System.Windows.Data;
3 
4 namespace Microscopic_Traffic_Simulator.Converters
5 {
9  class FromTimeSpanToHoursString : IValueConverter
10  {
19  public object Convert(object value, Type targetType, object parameter,
20  System.Globalization.CultureInfo culture)
21  {
22  TimeSpan valueTime = (TimeSpan)value;
23  if (valueTime == TimeSpan.MaxValue)
24  return string.Empty;
25  return string.Format("{0}:{1:00}:{2:00}.{3:000}", (int)valueTime.TotalHours,
26  valueTime.Minutes, valueTime.Seconds, valueTime.Milliseconds);
27  }
28 
37  public object ConvertBack(object value, Type targetType, object parameter,
38  System.Globalization.CultureInfo culture)
39  {
40  TimeSpan result;
41  if (TimeSpan.TryParse((string)value, out result))
42  {
43  return result;
44  }
45  else
46  {
47  return null;
48  }
49  }
50  }
51 }
object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Convert from TimeSpan to string representation HH:MM:SS.SSS
object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Not implemented conversion from string to TimeSpan