Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

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 }
System
Microscopic_Traffic_Simulator.Converters.FromSimulationSpeedToString.Convert
object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Convert simulation speed to string.
Definition: FromSimulationSpeedToString.cs:19
Microscopic_Traffic_Simulator.Converters.FromSimulationSpeedToString.ConvertBack
object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Convert string to simulation speed.
Definition: FromSimulationSpeedToString.cs:33
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12