-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converters.cs
127 lines (120 loc) · 3.1 KB
/
Converters.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Data;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace CardFilePBX
{
public class DbStateToBoolean : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (((ConnectionState)value) != ConnectionState.Broken)
return true;
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (Boolean)value ? ConnectionState.Closed : ConnectionState.Broken;
}
}
public class TariffConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var val = value as Tariff;
if (val.Name == "МегаТариф") return 0;
if (val.Name == "Максимум") return 1;
if (val.Name == "VIP") return 2;
if (val.Name == "Премиум") return 3;
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
Console.WriteLine(targetType);
return value;
}
}
public class InverseBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(bool))
return false;
return !(bool)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return !(bool)value;
}
}
public class CountToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Console.WriteLine((int)value);
if (targetType != typeof(bool))
return false;
return (int)value > 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return !(bool)value;
}
}
public static class TariffToInt
{
public static object Convert(object value)
{
string val;
if (value is Tariff)
{
val = (value as Tariff).Name;
}
else val = value as string;
if (val == "МегаТариф") return 0;
if (val == "Максимум") return 1;
if (val == "VIP") return 2;
if (val == "Премиум") return 3;
if (val == "0") return 0;
if (val == "1") return 1;
if (val == "2") return 2;
if (val == "3") return 3;
return 0;
}
public static object ConvertBack(object value)
{
return value;
}
}
public class BooleanToVisibility : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
{
if (parameter != null)
{
return (string)parameter == "1" ? Visibility.Collapsed : Visibility.Visible;
}
return Visibility.Visible;
}
if (parameter != null)
{
return (string)parameter == "1" ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((Visibility)value == Visibility.Visible)
{
return true;
}
else
{
return false;
}
}
}
}