Microscopic Traffic Simulator
FromSimulationSpeedToString.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 FromSimulationSpeedToString : IValueConverter
10  {
19  public object Convert(object value, Type targetType, object parameter,
20  System.Globalization.CultureInfo culture)
21  {
22  return value.ToString() + "x";
23  }
24 
33  public object ConvertBack(object value, Type targetType, object parameter,
34  System.Globalization.CultureInfo culture)
35  {
36  string valueString = (string)value;
37  double result;
38  int suffixLength = 1;
39  if (char.IsDigit(valueString[valueString.Length - 1]))
40  suffixLength = 0;
41  if (double.TryParse(
42  valueString.Substring(0, valueString.Length - suffixLength), out result))
43  {
44  return result;
45  }
46  else
47  {
48  return null;
49  }
50  }
51  }
52 }
object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Convert simulation speed to string.
object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Convert string to simulation speed.