Skip to content

Instantly share code, notes, and snippets.

@rockfordlhotka
Created June 11, 2018 02:27
Show Gist options
  • Save rockfordlhotka/819e1c090aceee65f72367e5094225b4 to your computer and use it in GitHub Desktop.
Save rockfordlhotka/819e1c090aceee65f72367e5094225b4 to your computer and use it in GitHub Desktop.
XAML bool to color converter
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