sabotage/Converters/BoolToColorConverter.cs
/// <summary>Converts a boolean to a SolidColorBrush.</summary>
/// <param name="value">Bolean value controlling wether to apply color change.</param>
/// <param name="targetType"></param>
/// <param name="parameter">Optional CSV string specifying the color names for both cases. Default is "DarkGreen;DarkRed".</param>
/// <param name="culture"></param>
/// <returns>A SolidColorBrush.</returns>
Converts a boolean to a SolidColorBrush.
Converts a boolean to a SolidColorBrush .
public object Convert(object value, Type targetType, object? parameter, CultureInfo culture) {
            var colorIfTrue = Colors.Green;
            var colorIfFalse = Colors.Red;
            var names = parameter?.ToString()?.Split(';');
            if (names?.Length > 0 && !string.IsNullOrEmpty(names[0])) {
                colorIfTrue = ColorFromName(names[0]);
            }
            if (names?.Length > 1 && !string.IsNullOrEmpty(names[1])) {
                colorIfFalse = ColorFromName(names[1]);
            }
            return new SolidColorBrush((bool)value ? colorIfTrue : colorIfFalse);
        }
public object Convert ( object value , Type targetType , object ? parameter , CultureInfo culture ) { var colorIfTrue = Colors . Green ; var colorIfFalse = Colors . Red ; var names = parameter ? . ToString ( ) ? . Split ( ' ' ) ; if ( names ? . Length > 0 && ! string . IsNullOrEmpty ( names [ 0 ] ) ) { colorIfTrue = ColorFromName ( names [ 0 ] ) ; } if ( names ? . Length > 1 && ! string . IsNullOrEmpty ( names [ 1 ] ) ) { colorIfFalse = ColorFromName ( names [ 1 ] ) ; } return new SolidColorBrush ( ( bool ) value ? colorIfTrue : colorIfFalse ) ; }
Converts a boolean to a SolidColorBrush.
Converts a boolean to a SolidColorBrush .
None
value
object
Bolean value controlling wether to apply color change.
Bolean value controlling wether to apply color change .
targetType
Type
None
parameter
object?
Optional CSV string specifying the color names for both cases. Default is "DarkGreen;DarkRed".
Optional CSV string specifying the color names for both cases . Default is " DarkGreen ; DarkRed " .
culture
CultureInfo
None