-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIoListTestingWindow.GridConverters.cs
More file actions
87 lines (78 loc) · 4.59 KB
/
Copy pathIoListTestingWindow.GridConverters.cs
File metadata and controls
87 lines (78 loc) · 4.59 KB
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
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using ArIED61850Tester.Models.IoTesting;
namespace ArIED61850Tester;
internal sealed class IoFatBooleanValueBrushConverter : IValueConverter
{
private static readonly Brush TrueBrush = Brush(229, 72, 77);
private static readonly Brush FalseBrush = Brush(22, 166, 106);
private static readonly Brush NeutralBrush = Brush(17, 24, 39);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var text = value?.ToString()?.Trim() ?? string.Empty;
if (text.Equals("True", StringComparison.OrdinalIgnoreCase) || text == "1") return TrueBrush;
if (text.Equals("False", StringComparison.OrdinalIgnoreCase) || text == "0") return FalseBrush;
return NeutralBrush;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
private static Brush Brush(byte r, byte g, byte b) { var value = new SolidColorBrush(Color.FromRgb(r, g, b)); value.Freeze(); return value; }
}
internal sealed class IoFatLiveBrushConverter : IValueConverter
{
private static readonly Brush LiveBrush = Brush(22, 132, 90);
private static readonly Brush MutedBrush = Brush(101, 117, 139);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is true ? LiveBrush : MutedBrush;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
private static Brush Brush(byte r, byte g, byte b) { var value = new SolidColorBrush(Color.FromRgb(r, g, b)); value.Freeze(); return value; }
}
internal sealed class IoFatEvidenceBrushConverter : IValueConverter
{
private static readonly Brush SuccessBrush = Brush(22, 132, 90);
private static readonly Brush MutedBrush = Brush(138, 151, 169);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value == null ? MutedBrush : SuccessBrush;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
private static Brush Brush(byte r, byte g, byte b) { var result = new SolidColorBrush(Color.FromRgb(r, g, b)); result.Freeze(); return result; }
}
internal sealed class IoFatQualityBrushConverter : IValueConverter
{
private static readonly Brush GoodBrush = Brush(22, 132, 90);
private static readonly Brush BadBrush = Brush(197, 58, 69);
private static readonly Brush MutedBrush = Brush(96, 112, 137);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var text = value?.ToString()?.Trim() ?? string.Empty;
if (text.Equals("good", StringComparison.OrdinalIgnoreCase)) return GoodBrush;
if (text.Contains("invalid", StringComparison.OrdinalIgnoreCase) || text.Contains("bad", StringComparison.OrdinalIgnoreCase)) return BadBrush;
return MutedBrush;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
private static Brush Brush(byte r, byte g, byte b) { var result = new SolidColorBrush(Color.FromRgb(r, g, b)); result.Freeze(); return result; }
}
internal sealed class IoFatStateBrushConverter : IValueConverter
{
private static readonly Brush PassBrush = Brush(22, 132, 90);
private static readonly Brush ReviewBrush = Brush(154, 101, 0);
private static readonly Brush FailBrush = Brush(197, 58, 69);
private static readonly Brush MutedBrush = Brush(96, 112, 137);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value switch
{
IoTestPointState.Passed => PassBrush,
IoTestPointState.Review => ReviewBrush,
IoTestPointState.Failed => FailBrush,
_ => MutedBrush
};
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
private static Brush Brush(byte r, byte g, byte b) { var result = new SolidColorBrush(Color.FromRgb(r, g, b)); result.Freeze(); return result; }
}
internal sealed class IoFatResultTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value switch
{
IoTestPointState.Passed => "✔ PASS",
IoTestPointState.Review => "⚠ REVIEW",
IoTestPointState.Failed => "✖ FAILED",
_ => "—"
};
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;
}