/// <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, targetType)); 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) { bool boolValue = value is bool && (bool)value; // Negate if needed if (ConverterTools.TryParseBool(parameter)) { boolValue = !boolValue; } return(ConverterTools.Convert(boolValue ? TrueValue : FalseValue, targetType)); }
/// <summary> /// Convert the <paramref name="value"/>'s Type 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 typeMatches = value != null && Type.Equals(value.GetType()); // Negate if needed if (ConverterTools.TryParseBool(parameter)) { typeMatches = !typeMatches; } return(ConverterTools.Convert(typeMatches ? TrueValue : FalseValue, 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) { 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 isEmpty = string.IsNullOrEmpty(value?.ToString()); // Negate if needed if (ConverterTools.TryParseBool(parameter)) { isEmpty = !isEmpty; } return(ConverterTools.Convert(isEmpty ? EmptyValue : NotEmptyValue, targetType)); }
/// <summary> /// Modifies the target data before passing it to the source object. This method is called only in TwoWay bindings. /// </summary> /// <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) { Visibility visibility = (Visibility)value; bool returnValue = visibility == Visibility.Visible; if (ConverterTools.TryParseBool(parameter)) { returnValue = !returnValue; } return(returnValue); }
/// <summary> /// Converts a string value into a Visibility value by testing if string is null or empty. /// </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 invert the converter logic.</param> /// <param name="language">The language of the conversion.</param> /// <returns>Visibility value.</returns> public object Convert(object value, Type targetType, object parameter, string language) { Visibility visibility = Visibility.Visible; if (string.IsNullOrEmpty(value?.ToString())) { visibility = Visibility.Collapsed; } if (ConverterTools.TryParseBool(parameter)) { return(visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible); } return(visibility); }
/// <summary> /// Convert a boolean value to visibility. /// </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) { Visibility visibility = Visibility.Collapsed; if (value is bool && (bool)value) { visibility = Visibility.Visible; } if (ConverterTools.TryParseBool(parameter)) { return(visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible); } return(visibility); }
/// <summary> /// This class return Visibility.Visible if the given collection is not empty or null. /// </summary> /// <param name="value">Collection to convert to Visibility.</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>Visibility.Visible if the collection is not null and not empty</returns> public object Convert(object value, Type targetType, object parameter, string language) { Visibility result = Visibility.Collapsed; IEnumerable <object> collection = value as IEnumerable <object>; if (collection != null && collection.Any()) { result = Visibility.Visible; } if (ConverterTools.TryParseBool(parameter)) { return(result == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible); } 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) { bool isEmpty = true; var collection = value as IEnumerable; if (collection != null) { var enumerator = collection.GetEnumerator(); isEmpty = !enumerator.MoveNext(); } // 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) { if (value == null) { return(NullValue); } double vd = 0.0; // DEFAULT? if (value is double dbl) { vd = dbl; } else if (double.TryParse(value.ToString(), out double result)) { vd = result; } var boolValue = false; if (GreaterThan != double.NaN && LessThan != double.NaN && vd > GreaterThan && vd < LessThan) { boolValue = true; } else if (GreaterThan != double.NaN && vd > GreaterThan) { boolValue = true; } else if (LessThan != double.NaN && vd < LessThan) { boolValue = true; } // Negate if needed if (ConverterTools.TryParseBool(parameter)) { boolValue = !boolValue; } return(ConverterTools.Convert(boolValue ? TrueValue : FalseValue, targetType)); }