|
3 | 3 | using System.Globalization;
|
4 | 4 | using System.Windows;
|
5 | 5 | using System.Windows.Data;
|
6 |
| -using System.Windows.Media; |
7 | 6 |
|
8 |
| -namespace OpenBullet2.Native.Converters |
| 7 | +namespace OpenBullet2.Native.Converters; |
| 8 | + |
| 9 | +// From https://stackoverflow.com/a/5182660/4332314 |
| 10 | +public class BooleanConverter<T> : IValueConverter |
9 | 11 | {
|
10 |
| - // From https://stackoverflow.com/a/5182660/4332314 |
11 |
| - public class BooleanConverter<T> : IValueConverter |
| 12 | + public BooleanConverter(T trueValue, T falseValue) |
12 | 13 | {
|
13 |
| - public BooleanConverter(T trueValue, T falseValue) |
14 |
| - { |
15 |
| - True = trueValue; |
16 |
| - False = falseValue; |
17 |
| - } |
| 14 | + True = trueValue; |
| 15 | + False = falseValue; |
| 16 | + } |
18 | 17 |
|
19 |
| - public T True { get; set; } |
20 |
| - public T False { get; set; } |
| 18 | + public T True { get; set; } |
| 19 | + public T False { get; set; } |
21 | 20 |
|
22 |
| - public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
23 |
| - => value is bool b && b ? True : False; |
| 21 | + public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
| 22 | + => value is bool b && b ? True : False; |
24 | 23 |
|
25 |
| - public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
26 |
| - => value is T convertedValue && EqualityComparer<T>.Default.Equals(convertedValue, True); |
27 |
| - } |
| 24 | + public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
| 25 | + => value is T convertedValue && EqualityComparer<T>.Default.Equals(convertedValue, True); |
| 26 | +} |
28 | 27 |
|
29 |
| - public sealed class BoolToVisibilityConverter : BooleanConverter<Visibility> |
| 28 | +public sealed class BoolToVisibilityConverter : BooleanConverter<Visibility> |
| 29 | +{ |
| 30 | + public BoolToVisibilityConverter() : |
| 31 | + base(Visibility.Visible, Visibility.Collapsed) |
30 | 32 | {
|
31 |
| - public BoolToVisibilityConverter() : |
32 |
| - base(Visibility.Visible, Visibility.Collapsed) |
33 |
| - { |
34 | 33 |
|
35 |
| - } |
36 | 34 | }
|
| 35 | +} |
37 | 36 |
|
38 |
| - public sealed class BoolToThicknessConverter : BooleanConverter<Thickness> |
| 37 | +public sealed class BoolToThicknessConverter : BooleanConverter<Thickness> |
| 38 | +{ |
| 39 | + public BoolToThicknessConverter() : |
| 40 | + base(new Thickness(1), new Thickness(0)) |
39 | 41 | {
|
40 |
| - public BoolToThicknessConverter() : |
41 |
| - base(new Thickness(1), new Thickness(0)) |
42 |
| - { |
43 | 42 |
|
44 |
| - } |
45 | 43 | }
|
| 44 | +} |
46 | 45 |
|
47 |
| - public sealed class BoolToTextWrappingConverter : BooleanConverter<TextWrapping> |
| 46 | +public sealed class BoolToTextWrappingConverter : BooleanConverter<TextWrapping> |
| 47 | +{ |
| 48 | + public BoolToTextWrappingConverter() : |
| 49 | + base(TextWrapping.Wrap, TextWrapping.NoWrap) |
48 | 50 | {
|
49 |
| - public BoolToTextWrappingConverter() : |
50 |
| - base(TextWrapping.Wrap, TextWrapping.NoWrap) |
51 |
| - { |
52 | 51 |
|
53 |
| - } |
54 | 52 | }
|
55 | 53 | }
|
0 commit comments