/// <summary> /// Convert back the value to a boolean /// </summary> /// <remarks>If the <paramref name="value"/> parameter is a reference type, <see cref="TrueValue"/> must match its reference to return true.</remarks> /// <param name="value">The target data being passed to the source.</param> /// <param name="targetType">The type of the target property, as a type reference (System.Type for Microsoft .NET, a TypeName helper struct for Visual C++ component extensions (C++/CX)).</param> /// <param name="parameter">An optional parameter to be used to invert the converter logic.</param> /// <param name="language">The language of the conversion.</param> /// <returns>The value to be passed to the source object.</returns> public object ConvertBack(object value, Type targetType, object parameter, string language) { bool result = Equals(value, ConverterTools.Convert(TrueValue, value.GetType())); if (ConverterTools.TryParseBool(parameter)) { result = !result; } return(result); }
/// <summary> /// Convert a boolean value to an other object. /// </summary> /// <param name="value">The source data being passed to the target.</param> /// <param name="targetType">The type of the target property, as a type reference.</param> /// <param name="parameter">An optional parameter to be used to invert the converter logic.</param> /// <param name="language">The language of the conversion.</param> /// <returns>The value to be passed to the target dependency property.</returns> public object Convert(object value, Type targetType, object parameter, string language) { var isEmpty = CheckValueIsEmpty(value); // Negate if needed if (ConverterTools.TryParseBool(parameter)) { isEmpty = !isEmpty; } return(ConverterTools.Convert(isEmpty ? EmptyValue : NotEmptyValue, targetType)); }
/// <summary> /// Convert a boolean value to an other object. /// </summary> /// <param name="value">The source data being passed to the target.</param> /// <param name="targetType">The type of the target property, as a type reference.</param> /// <param name="parameter">An optional parameter to be used to invert the converter logic.</param> /// <param name="language">The language of the conversion.</param> /// <returns>The value to be passed to the target dependency property.</returns> public object Convert(object value, Type targetType, object parameter, string language) { bool boolValue = value is bool && (bool)value; // Negate if needed if (ConverterTools.TryParseBool(parameter)) { boolValue = !boolValue; } return(ConverterTools.Convert(boolValue ? TrueValue : FalseValue, targetType)); }