Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

EnumMatchToBooleanConverter.cs
Go to the documentation of this file.
1 using System;
2 using System.Globalization;
3 using System.Windows.Data;
4
5 namespace Microscopic_Traffic_Simulator.Converters
6 {
10 public class EnumMatchToBooleanConverter : IValueConverter
11 {
20 public object Convert(object value, Type targetType,
21 object parameter, CultureInfo culture)
22 {
23 if (value == null || parameter == null)
24 return false;
25
26 string checkValue = value.ToString();
27 string targetValue = parameter.ToString();
28 return checkValue.Equals(targetValue,
29 StringComparison.InvariantCultureIgnoreCase);
30 }
31
40 public object ConvertBack(object value, Type targetType,
41 object parameter, CultureInfo culture)
42 {
43 if (value == null || parameter == null)
44 return null;
45
46 bool useValue = (bool)value;
47 string targetValue = parameter.ToString();
48 if (useValue)
49 return Enum.Parse(targetType, targetValue);
50
51 return null;
52 }
53 }
54 }
System
Microscopic_Traffic_Simulator.Converters.EnumMatchToBooleanConverter.Convert
object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Converts enum value to boolean
Definition: EnumMatchToBooleanConverter.cs:20
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12
Microscopic_Traffic_Simulator.Converters.EnumMatchToBooleanConverter.ConvertBack
object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Converts boolean to enum value.
Definition: EnumMatchToBooleanConverter.cs:40
Microscopic_Traffic_Simulator.Converters.EnumMatchToBooleanConverter
Converts enum value to boolean and vice versa.
Definition: EnumMatchToBooleanConverter.cs:10