comparison 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
comparison
equal deleted inserted replaced
68:81337ebf885a 69:a0bcd783e612
1 // original code: http://geekswithblogs.net/codingbloke/archive/2010/05/28/a-generic-boolean-value-converter.aspx
2
3 using System;
4 using System.Globalization;
5 using System.Windows.Data;
6
7 namespace SilverlightGlimpse.Converters
8 {
9 public class BoolToValueConverter<T> : IValueConverter
10 {
11 public T FalseValue { get; set; }
12 public T TrueValue { get; set; }
13
14 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
15 {
16 if (value == null)
17 return FalseValue;
18 else
19 return (bool)value ? TrueValue : FalseValue;
20 }
21
22 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
23 {
24 return value != null && value.Equals(TrueValue);
25 }
26 }
27 }