// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Defines the BooleanToVisibilityConverter type. // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Converters { using System; using System.Globalization; using System.Windows; using System.Windows.Data; /// /// Boolean to Visibility Converter /// public sealed class BooleanToVisibilityConverter : IValueConverter { /// /// Convert a boolean to visibility property. /// /// /// The value. /// /// /// The target type. /// /// /// The parameter. (A boolean which inverts the output) /// /// /// The culture. /// /// /// Visibility property /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // Paramater is a boolean which inverts the output. var param = System.Convert.ToBoolean(parameter, CultureInfo.InvariantCulture); if (value == null) { return Visibility.Collapsed; } if (value is bool) { if (param) { return (bool)value ? Visibility.Collapsed : Visibility.Visible; } else { return (bool)value ? Visibility.Visible : Visibility.Collapsed; } } return value; } /// /// Convert Back for the IValueConverter Interface. Not used! /// /// /// The value. /// /// /// The target type. /// /// /// The parameter. /// /// /// The culture. /// /// /// Nothing /// /// /// This method is not used! /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }