1
1
using Avalonia . Data ;
2
2
using Avalonia . Data . Converters ;
3
3
using Avalonia . Media . Imaging ;
4
+ using Common . Enums ;
4
5
using Common . Helpers ;
5
6
using System . Globalization ;
6
7
@@ -27,6 +28,54 @@ public sealed class ImagePathToBitmapConverter : IValueConverter
27
28
28
29
public object ConvertBack ( object ? value , Type targetType , object ? parameter , CultureInfo culture )
29
30
{
30
- return new BindingNotification ( new NotImplementedException ( "ConvertBack method for ImagePathToBitmapConverter is not implemented." ) ) ;
31
+ return new BindingNotification ( new NotImplementedException ( $ "ConvertBack method for { nameof ( ImagePathToBitmapConverter ) } is not implemented.") ) ;
32
+ }
33
+ }
34
+
35
+ public sealed class GameStringToEnumConverter : IValueConverter
36
+ {
37
+ public object Convert ( object ? value , Type targetType , object ? parameter , CultureInfo culture )
38
+ {
39
+ if ( value is not GameEnum valueEnum )
40
+ {
41
+ return false ;
42
+ }
43
+
44
+ if ( parameter is not string paramStr )
45
+ {
46
+ throw new NotImplementedException ( ) ;
47
+ }
48
+
49
+ if ( ! Enum . TryParse < GameEnum > ( paramStr , out var gameEnum ) )
50
+ {
51
+ throw new NotImplementedException ( ) ;
52
+ }
53
+
54
+ return valueEnum == gameEnum ;
55
+ }
56
+
57
+ public object ConvertBack ( object ? value , Type targetType , object ? parameter , CultureInfo culture )
58
+ {
59
+ if ( value is not bool valueBool )
60
+ {
61
+ return AvaloniaProperty . UnsetValue ;
62
+ }
63
+
64
+ if ( parameter is not string paramStr )
65
+ {
66
+ throw new NotImplementedException ( ) ;
67
+ }
68
+
69
+ if ( ! valueBool )
70
+ {
71
+ return AvaloniaProperty . UnsetValue ;
72
+ }
73
+
74
+ if ( ! Enum . TryParse < GameEnum > ( paramStr , out var gameEnum ) )
75
+ {
76
+ throw new NotImplementedException ( ) ;
77
+ }
78
+
79
+ return gameEnum ;
31
80
}
32
81
}
0 commit comments