Mercurial > silverbladetech
view SilverlightGlimpse/SilverlightGlimpse/Converters/BoolToValueConverter.cs @ 69:a0bcd783e612
Latest work
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Mon, 23 Apr 2012 11:06:10 +0100 |
parents | |
children | 96e6fbd70f49 |
line wrap: on
line source
// original code: http://geekswithblogs.net/codingbloke/archive/2010/05/28/a-generic-boolean-value-converter.aspx using System; using System.Globalization; using System.Windows.Data; namespace SilverlightGlimpse.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, CultureInfo culture) { if (value == null) return FalseValue; else return (bool)value ? TrueValue : FalseValue; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value != null && value.Equals(TrueValue); } } }