using System; using System.Globalization; using System.Windows; using System.Windows.Data; namespace VersOne.Epub.WpfDemo.Utils { /// /// XAML data converter which converts false to /// and true to or (depending on the supplied additional parameter). /// public class BooleanToInverseVisibilityConverter : IValueConverter { /// /// Converts false to /// and true to or (depending on the value of the ). /// /// Boolean value to convert from. /// The type of the binding target property. Not used in this converter. /// /// Additional parameter which determines whether true value should be converted to (if the parameter is null) /// or to (if the parameter is not null). /// /// The culture for the conversion. Not used in this converter. /// /// if the is false and /// or (depending on the value of the ) /// if the is true. /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is bool)) { return Visibility.Hidden; } if (!(bool)value) { return Visibility.Visible; } else if (parameter != null) { return Visibility.Collapsed; } else { return Visibility.Hidden; } } /// /// Performs a backwards conversion. Not used in this converter. /// /// The value that is produced by the binding target. /// The type to convert to. /// The converter parameter to use. /// The culture to use in the converter. /// This method always returns null. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } } }