public Convert ( object value, Type targetType, object parameter, |
||
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 | 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."); } }
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); }
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); }