/// <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, CultureInfo culture)
        {
            bool result = Equals(value, ConverterTools.Convert(TrueValue, value.GetType()));

            if (ConverterTools.TryParseBool(parameter))
            {
                result = !result;
            }

            return(result);
        }
コード例 #2
0
        /// <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, CultureInfo culture)
        {
            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, CultureInfo culture)
        {
            bool boolValue = value is bool boolean && boolean;

            // Negate if needed
            if (ConverterTools.TryParseBool(parameter))
            {
                boolValue = !boolValue;
            }

            return(ConverterTools.Convert(boolValue ? 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, CultureInfo culture)
        {
            var isEmpty = CheckValueIsEmpty(value);

            // Negate if needed
            if (ConverterTools.TryParseBool(parameter))
            {
                isEmpty = !isEmpty;
            }

            return(ConverterTools.Convert(isEmpty ? EmptyValue : NotEmptyValue, targetType));
        }
コード例 #5
0
        /// <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, CultureInfo culture)
        {
            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));
        }