/// <summary>Converts a value. </summary> /// <returns>A converted value. If the method returns null, the valid null value is used.</returns> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is bool)) { return(value); } return(LogicInverter.InvertIfNecessary((bool)value, _isInverted, Visibility.Visible, _nonVisibleState)); }
/// <summary>Converts a value. </summary> /// <returns>A converted value. If the method returns null, the valid null value is used.</returns> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && !(value is string)) { throw new ArgumentException($"value must be of type '{typeof(string)}'"); } var retVal = LogicInverter.InvertIfNecessary(_stringTest((string)value), _isInverted, true, false); return(retVal); }
/// <summary>Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.</summary> /// <returns>A converted value.If the method returns null, the valid null value is used.A return value of <see cref="T:System.Windows.DependencyProperty" />.<see cref="F:System.Windows.DependencyProperty.UnsetValue" /> indicates that the converter did not produce a value, and that the binding will use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue" /> if it is available, or else will use the default value.A return value of <see cref="T:System.Windows.Data.Binding" />.<see cref="F:System.Windows.Data.Binding.DoNothing" /> indicates that the binding does not transfer the value or use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue" /> or the default value.</returns> /// <param name="values">The array of values that the source bindings in the <see cref="T:System.Windows.Data.MultiBinding" /> produces. The value <see cref="F:System.Windows.DependencyProperty.UnsetValue" /> indicates that the source binding has no value to provide for conversion.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Any(x => x == DependencyProperty.UnsetValue)) { return(values); } if (!values.Any()) { throw new ArgumentException($"'{nameof(values)}' must contain atleast one boolean."); } if (values.Any(v => !(v is bool))) { throw new ArgumentException($"'{nameof(values)}' must contain only booleans."); } var bools = values.Cast <bool>(); return(LogicInverter.InvertIfNecessary(_combine(bools), _isInverted, true, false)); }
/// <summary>Converts a value. </summary> /// <returns>A converted value. If the method returns null, the valid null value is used.</returns> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(LogicInverter.InvertIfNecessary(value == null, _isInverted, true, false)); }