Created
June 11, 2018 02:27
-
-
Save rockfordlhotka/819e1c090aceee65f72367e5094225b4 to your computer and use it in GitHub Desktop.
XAML bool to color converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Globalization; | |
using System.Text; | |
using Xamarin.Forms; | |
namespace ProjectTracker.Ui.Xamarin.Xaml | |
{ | |
public class BoolColorConverter : IValueConverter | |
{ | |
public Color TrueColor { get; set; } | |
public Color FalseColor { get; set; } | |
public bool Invert { get; set; } | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
var v = (bool)value; | |
if (Invert) | |
v = !v; | |
if (v) | |
return TrueColor; | |
else | |
return FalseColor; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment