using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; namespace butterflow_ui { /// A visibility converter. [ValueConversion(typeof(bool), typeof(Visibility))] public class BoolVisibilityConverter : IValueConverter { /// Converts a value. /// Thrown when an object cannot be cast to a required /// type. /// The value produced by the binding source. /// The type of the binding target property. /// The converter parameter to use. /// The culture to use in the converter. /// /// A converted value. If the method returns , the valid null value is /// used. /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType == typeof(Visibility)) { return (bool)value ? Visibility.Visible : Visibility.Hidden; } throw new InvalidCastException(string.Format("Cannot convert type to {0} from bool.", targetType.Name)); } /// Converts a value. /// Thrown when an object cannot be cast to a required /// type. /// 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. /// /// A converted value. If the method returns , the valid null value is /// used. /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType == typeof(Visibility)) { return ((Visibility)value == Visibility.Visible) ? true : false; } throw new InvalidCastException(string.Format("Cannot convert type {0} to boolean.", targetType.Name)); } } }