Convert() public method

Convertes the boolean value parameter to a visibility value. True converts to visible and false converts to collapsed.
public Convert ( object value, Type targetType, object parameter, CultureInfo culture ) : object
value object The boolean value that is to be converted.
targetType Type The type to which the value is to be converted. In this case it is always .
parameter object A parameter for the conversion. Not used in this converter, so it should always be null.
culture System.Globalization.CultureInfo The culture information of the current culture, so that parsing can be adjusted to cultural conventions.
return object
        /// <summary>
        /// Converts a <see cref="bool"/> value to a <see cref="Visibility"/> enumeration value.
        /// </summary>
        /// <param name="value">The <see cref="bool"/> value to convert. This can also be a <see cref="Nullable{Boolean}"/> value.</param>
        /// <param name="targetType">This parameter is not used.</param>
        /// <param name="parameter">This parameter is not used.</param>
        /// <param name="culture">This parameter is not used.</param>
        /// <returns>Returns <see cref="Visibility.Collapsed"/> if the value is true, otherwise <see cref="Visibility.Visible"/>.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool?)
            {
                if (true == (bool?)value)
                {
                    value = false;
                }
                else
                {
                    value = true;
                }

                //var inverseValue = ((bool?)value).HasValue ? !((bool)value);
                return(converter.Convert(value, targetType, parameter, culture));
            }
            else if (value is bool)
            {
                var inverseValue = !((bool)value);
                return(converter.Convert(inverseValue, targetType, parameter, culture));
            }
            else
            {
                throw new InvalidOperationException("The value parameter must be of type System.Boolean.");
            }
        }
Exemplo n.º 2
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
    if (value is bool b) {
       if (parameter == null) return b ? Visibility.Visible : Visibility.Collapsed;
       if (parameter is Visibility v && v == Visibility.Hidden) return b ? Visibility.Visible : Visibility.Hidden;
    }
    return core.Convert(value, targetType, parameter, culture);
 }
Exemplo n.º 3
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(_converter.Convert((bool)value, targetType, parameter, culture));
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     var c = new BooleanToVisibilityConverter();
     return c.Convert(!(bool)value, targetType, parameter, culture);
 }