ModernWPF.Converters.MultiBoolVisibleConverter.Convert C# (CSharp) Method

Convert() public method

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.
public Convert ( object values, Type targetType, object parameter, System culture ) : object
values object The array of values that the source bindings in the produces. The value indicates that the source binding has no value to provide for conversion.
targetType System.Type The type of the binding target property.
parameter object The converter parameter to use.
culture System The culture to use in the converter.
return object
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool? retVal = null;
            if (values != null)
            {
                foreach (var val in values)
                {
                    var asBool = val as bool?;
                    if (asBool != null)
                    {
                        if (retVal.HasValue) { retVal = retVal.Value && asBool.Value; }
                        else { retVal = asBool.Value; }
                    }
                    else
                    {
                        var asVis = val as Visibility?;
                        if (asVis != null)
                        {
                            if (retVal.HasValue) { retVal = retVal.Value && (asVis.Value == Visibility.Visible); }
                            else { retVal = asVis.Value == Visibility.Visible; }
                        }
                    }
                }
            }
            if (parameter != null && string.Equals("not", parameter.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                retVal = !retVal.GetValueOrDefault();
            }
            return retVal.GetValueOrDefault() ? Visibility.Visible : Visibility.Collapsed;
        }

Usage Example

        public void True_Array_Converts_To_Visible()
        {
            var conv = new MultiBoolVisibleConverter();

            var result = conv.Convert(new object[] { true, true }, typeof(Visibility), null, CultureInfo.CurrentCulture);

            Assert.AreEqual(Visibility.Visible, result);
        }
All Usage Examples Of ModernWPF.Converters.MultiBoolVisibleConverter::Convert
MultiBoolVisibleConverter