Last active
December 16, 2015 17:18
-
-
Save ScottIsAFool/5468967 to your computer and use it in GitHub Desktop.
A base converter that can be used to create converters that require a true/false value.
This file contains hidden or 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.Windows.Data; | |
namespace ScottIsAFool.WindowsPhone.Converters | |
{ | |
public class BoolToValueConverter<T> : IValueConverter | |
{ | |
public T FalseValue { get; set; } | |
public T TrueValue { get; set; } | |
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | |
{ | |
if (value == null) | |
return FalseValue; | |
else | |
return (bool)value ? TrueValue : FalseValue; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | |
{ | |
return value != null ? value.Equals(TrueValue) : false; | |
} | |
} | |
// Sample Converter that can be used for an int | |
//public class BooleanToIntConverter : BooleanToValueConverter<int> | |
//{ | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment