Пример #1
0
 public MultiBindingCreator(string path, FrameworkElement element, List<string> canvasPaths, string elementName,
                             DependencyProperty property, IMultiValueConverter converter)
     : base(path, element, elementName,property)
 {
     _canvasPaths = canvasPaths;
     _converter = converter;
 }
Пример #2
0
 public MultiBind(IMultiValueConverter converter, object b1, object b2, object b3,
                  object b4, object b5, object b6)
 {
     Converter = converter;
     CheckOneWay();
     AddBinding(b1);
     AddBinding(b2);
     AddBinding(b3);
     AddBinding(b4);
     AddBinding(b5);
     AddBinding(b6);
 }
Пример #3
0
        private object ConvertValue(IList <object> values, Type targetType, IMultiValueConverter converter)
        {
            var culture   = CultureInfo.CurrentCulture;
            var converted = converter.Convert(values, targetType, ConverterParameter, culture);

            if (converted == AvaloniaProperty.UnsetValue && FallbackValue != null)
            {
                converted = FallbackValue;
            }

            return(converted);
        }
 internal static void AssertBindingExists <TDest>(
     BindableObject bindable,
     BindableProperty targetProperty,
     IList <BindingBase> bindings,
     IMultiValueConverter converter = null,
     BindingMode mode = BindingMode.Default,
     bool assertConverterInstanceIsAnyNotNull = false,
     string stringFormat   = null,
     TDest targetNullValue = default,
     TDest fallbackValue   = default,
     Action <IMultiValueConverter> assertConvert = null)
 => AssertBindingExists <TDest, object>(
     bindable, targetProperty, bindings, converter, null, mode, assertConverterInstanceIsAnyNotNull,
     stringFormat, targetNullValue, fallbackValue, assertConvert);
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiChained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="multiConverter">The multi-value converter.</param>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 /// <param name="converter4">The fourth value converter.</param>
 /// <param name="converter5">The fifth value converter.</param>
 /// <param name="converter6">The sixth value converter.</param>
 /// <param name="converter7">The seventh value converter.</param>
 /// <param name="converter8">The eighth value converter.</param>
 public MultiChained(IMultiValueConverter multiConverter, IValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4,
                     IValueConverter converter5, IValueConverter converter6, IValueConverter converter7, IValueConverter converter8)
 {
     chainedConverter = new Chained();
     MultiConverter   = multiConverter;
     Converter1       = converter1;
     Converter2       = converter2;
     Converter3       = converter3;
     Converter4       = converter4;
     Converter5       = converter5;
     Converter6       = converter6;
     Converter7       = converter7;
     Converter8       = converter8;
 }
Пример #6
0
        private object ConvertValue(IList <object> values, Type targetType, IMultiValueConverter converter)
        {
            var culture   = CultureInfo.CurrentCulture;
            var converted = converter.Convert(values, targetType, ConverterParameter, culture);

            if (converted == BindingOperations.DoNothing)
            {
                return(converted);
            }

            if (converted == AvaloniaProperty.UnsetValue)
            {
                converted = FallbackValue;
            }

            return(converted);
        }
        internal static IMultiValueConverter AssertConvert <TConvertedValue>(this IMultiValueConverter converter, object[] values, object parameter, TConvertedValue expectedConvertedValue, bool twoWay = false, bool backOnly = false, CultureInfo culture = null)
        {
            Assert.That(converter?.Convert(values, typeof(TConvertedValue), parameter, culture), Is.EqualTo(backOnly ? BindableProperty.UnsetValue : expectedConvertedValue));
            var convertedBackValues = converter?.ConvertBack(expectedConvertedValue, null, parameter, culture);

            if (twoWay || backOnly)
            {
                Assert.That(convertedBackValues.Length, Is.EqualTo(values.Length));
                for (int i = 0; i < values.Length; i++)
                {
                    Assert.That(convertedBackValues[i], Is.EqualTo(values[i]));
                }
            }
            else
            {
                Assert.That(convertedBackValues, Is.Null);
            }
            return(converter);
        }
Пример #8
0
        private static void Bind(DependencyObject target, DependencyProperty prop, IMultiValueConverter converter, params System.Linq.Expressions.Expression[] expressions)
        {
            var multiBinding = new MultiBinding();

            multiBinding.Converter = converter;

            foreach (var expression in expressions)
            {
                var targetAndMember = expression.GetTargetAndMember();
                var bindingSource   = targetAndMember.Item1;
                var member          = targetAndMember.Item2;

                var binding = new Binding(member.Name);
                binding.Source = bindingSource;
                multiBinding.Bindings.Add(binding);
            }

            BindingOperations.SetBinding(target, prop, multiBinding);
        }
Пример #9
0
        /// <summary>
        /// Converts a value by iterating in reverse order through the <see cref="Converters"/> collection and executing <see cref="IValueConverter.ConvertBack"/> method for each <see cref="IValueConverter"/> contained, next executing <see cref="IMultiValueConverter.ConvertBack"/> method of the <see cref="Converter"/>. The return value of the <see cref="IValueConverter.ConvertBack"/> method call for current <see cref="IValueConverter"/> in the iteration is passed as input value for processing next <see cref="IValueConverter"/> in the iteration or processing the <see cref="Converter"/>.
        /// </summary>
        /// <param name="value">The value that is produced by the binding target.</param>
        /// <param name="targetTypes">The array of types to convert to. The array length indicates the number and types of values that are suggested for the method to return.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>An array of values that have been converted from the target value back to the source values, meaning the result of processing the reversed chain of converters.</returns>
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            IMultiValueConverter converter = Converter;

            if (converter != null)
            {
                for (int i = converters.Count - 1; i >= 0; i--)
                {
                    value = converters[i].ConvertBack(value, typeof(object), parameter, culture);

                    if (value == Binding.DoNothing)
                    {
                        return(null);
                    }
                }

                return(converter.ConvertBack(value, targetTypes, parameter, culture));
            }

            return(null);
        }
 /// <summary>Bind to a specified property with multiple bindings and a multi convertor</summary>
 public static TBindable Bind <TBindable>(
     this TBindable bindable,
     BindableProperty targetProperty,
     IList <BindingBase> bindings,
     IMultiValueConverter converter,
     object?converterParameter = default,
     BindingMode mode          = BindingMode.Default,
     string?stringFormat       = null,
     object?targetNullValue    = null,
     object?fallbackValue      = null) where TBindable : BindableObject
 {
     bindable.SetBinding(targetProperty, new MultiBinding
     {
         Bindings           = bindings,
         Converter          = converter,
         ConverterParameter = converterParameter,
         Mode            = mode,
         StringFormat    = stringFormat,
         TargetNullValue = targetNullValue,
         FallbackValue   = fallbackValue
     });
     return(bindable);
 }
Пример #11
0
        private object ConvertValue(IList <object> values, Type targetType, IMultiValueConverter converter)
        {
            for (var i = 0; i < values.Count; ++i)
            {
                if (values[i] is BindingNotification notification)
                {
                    values[i] = notification.Value;
                }
            }

            var culture = CultureInfo.CurrentCulture;

            values = new System.Collections.ObjectModel.ReadOnlyCollection <object>(values);
            object converted;

            if (converter != null)
            {
                converted = converter.Convert(values, targetType, ConverterParameter, culture);
            }
            else
            {
                converted = values;
            }

            if (converted == null)
            {
                converted = TargetNullValue;
            }

            if (converted == AvaloniaProperty.UnsetValue)
            {
                converted = FallbackValue;
            }

            return(converted);
        }
Пример #12
0
 public MultiBind(IMultiValueConverter converter, object b1)
 {
     Converter = converter;
     CheckOneWay();
     AddBinding(b1);
 }
Пример #13
0
 public void Deconstruct(out IMultiValueConverter converter, out Type target, out object parameter)
 {
     converter = Converter;
     target    = ConvertTargetType;
     parameter = ConverterParameter;
 }
Пример #14
0
 /// <summary>
 /// Creates a new instance of <see cref="Aggregator"/> and initializes with the passed converters.
 /// </summary>
 public Aggregator(IMultiValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4)
 {
     Converters = new object[] { converter1, converter2, converter3, converter4 };
 }
Пример #15
0
 public void DeconstructBack(out IMultiValueConverter converter, out Type[] target, out object parameter)
 {
     converter = Converter;
     target    = ConvertBackTargetTypes;
     parameter = ConverterParameter;
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiChained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="multiConverter">The multi-value converter.</param>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 public MultiChained(IMultiValueConverter multiConverter, IValueConverter converter1, IValueConverter converter2)
     : this(multiConverter, converter1, converter2, null, null, null, null, null, null)
 {
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiChained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="multiConverter">The multi-value converter.</param>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 /// <param name="converter4">The fourth value converter.</param>
 /// <param name="converter5">The fifth value converter.</param>
 public MultiChained(IMultiValueConverter multiConverter, IValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4,
                     IValueConverter converter5)
     : this(multiConverter, converter1, converter2, converter3, converter4, converter5, null, null, null)
 {
 }
 IMultiSourceBindingOptions IConverterSelection <IMultiSourceBindingOptions, IMultiValueConverter> .
 WithConverter(IMultiValueConverter converter)
 {
     _binding.Converter = converter;
     return(this);
 }
Пример #19
0
 public MultiValueConverterWrapper(IMultiValueConverter multiValueConverter, string stringFormat)
 {
     _multiValueConverter = multiValueConverter;
     _stringFormat        = stringFormat;
 }
Пример #20
0
        public MultiConverterArrayMultiParametersParameter(IList<IValueConverter> converters, IMultiValueConverter converter, object parameter, IList<object> parameters)
        {
            if (converters.Count != parameters.Count) throw new ArgumentException("converters and parameters does not have the same number of parameters.");

            Converter = converter;

            Converters = converters;

            Parameter = parameter;

            Parameters = parameters;
        }
Пример #21
0
        //...

        public static BindingExpressionBase MultiBind(this DependencyObject input, DependencyProperty property, IMultiValueConverter converter, params Binding[] bindings)
        {
            var result = new MultiBinding()
            {
                Converter = converter,
                Mode      = BindingMode.OneWay,
            };

            if (bindings?.Length > 0)
            {
                bindings.ForEach(i => result.Bindings.Add(i));
            }

            return(input.Bind(property, result));
        }
Пример #22
0
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(DependencyProperty.UnsetValue);
            }
            object[] unconvertedValues = (object[])value;
            object   converter         = Converter;

            object result = unconvertedValues;

            if (converter != null)
            {
                object converterParameter = ConverterParameter;
                SourceValuesErrors = null;
                try
                {
                    IMultiValueConverter multiConverter = converter as IMultiValueConverter;
                    if (multiConverter != null)
                    {
                        result = multiConverter.Convert(unconvertedValues, targetType, converterParameter, culture);
                    }
                    else
                    {
                        IValueConverter singleConverter = converter as IValueConverter;
                        if (singleConverter != null)
                        {
                            result = singleConverter.Convert(unconvertedValues[0], targetType, converterParameter, culture);
                        }
                    }
                }
                catch (Exception ex)
                {
                    SourceValuesErrors = new MultiBindingValidationError[] { new MultiBindingValidationError(ex) };
                    if (MultiBinding.ValidatesOnExceptions)
                    {
                        return(DependencyProperty.UnsetValue);
                    }
                    throw;
                }
            }


            if (result != DependencyProperty.UnsetValue)
            {
                String format = StringFormat;
                if (format != null)
                {
                    format = Regex.Replace(format, @"%(\d+)", "{$1}");
                    if (result is Object[])
                    {
                        result = String.Format(culture, format, (Object[])result);
                    }
                    else
                    {
                        result = String.Format(culture, format, result);
                    }
                }
            }
            return(result);
        }
Пример #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiChained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="multiConverter">The multi-value converter.</param>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 /// <param name="converter4">The fourth value converter.</param>
 /// <param name="converter5">The fifth value converter.</param>
 /// <param name="converter6">The sixth value converter.</param>
 /// <param name="converter7">The seventh value converter.</param>
 /// <param name="converter8">The eighth value converter.</param>
 public MultiChained(IMultiValueConverter multiConverter, IValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4,
                     IValueConverter converter5, IValueConverter converter6, IValueConverter converter7, IValueConverter converter8)
 {
     chainedConverter = new Chained();
     MultiConverter = multiConverter;
     Converter1 = converter1;
     Converter2 = converter2;
     Converter3 = converter3;
     Converter4 = converter4;
     Converter5 = converter5;
     Converter6 = converter6;
     Converter7 = converter7;
     Converter8 = converter8;
 }
Пример #24
0
 /// <summary>
 /// 初始化 <see cref="MultiDataBinding"/> 新实例。
 /// </summary>
 /// <param name="propertyName">绑定的属性名称。</param>
 /// <param name="value">绑定源。</param>
 /// <param name="converter">转换器。</param>
 /// <param name="convertParameter">转换参数。</param>
 public MultiDataBinding(string propertyName, MultiBindableValue value, IMultiValueConverter converter, object convertParameter) : this(propertyName, value, converter, convertParameter, null)
 {
 }
 /// <summary>
 /// Traces an error for the specified converter.
 /// </summary>
 /// <param name="converter">The converter.</param>
 /// <param name="message">The message.</param>
 /// <param name="methodName">Name of the calling method.</param>
 public static void TraceError([NotNull] this IMultiValueConverter converter, [NotNull] string message, [NotNull] string methodName)
 {
     InternalTraceError(converter, message, methodName);
 }
 internal static IMultiValueConverter AssertConvert <TConvertedValue>(this IMultiValueConverter converter, object[] values, TConvertedValue expectedConvertedValue, bool twoWay = false, bool backOnly = false, CultureInfo culture = null)
 => AssertConvert <TConvertedValue>(converter, values, null, expectedConvertedValue, twoWay, backOnly, culture);
Пример #27
0
 public MultiValueBinding(IEnumerable <IValueProvider> valueProviders, IMultiValueConverter converter)
 {
     ValueProviders = valueProviders?.ToArray() ?? throw new ArgumentNullException(nameof(valueProviders));
     Converter      = converter;
 }
Пример #28
0
 public AsyncMultiValueConverter(IMultiValueConverter converter)
 {
     Converter = converter;
 }
 /// <summary>
 /// Runs Convert with TargetType, Parameter and Culture = null
 /// </summary>
 /// <typeparam name="TOutput">The expected output</typeparam>
 /// <param name="valueConverter">The value converter</param>
 /// <param name="inputs">The inputs to use for the converter</param>
 /// <returns></returns>
 public static TOutput Convert <TOutput>(this IMultiValueConverter valueConverter, object[] inputs)
 {
     return((TOutput)valueConverter.Convert(inputs, null, null, null));
 }
Пример #30
0
 /// <summary>
 /// 绑定多个指定的值到属性,并使用指定的转换器。
 /// </summary>
 /// <param name="value">绑定的值。</param>
 /// <param name="converter">更新时,值转换器。</param>
 /// <param name="convertParameter">转换参数。</param>
 /// <param name="culture">区域信息。</param>
 /// <returns>返回已绑定的 <see cref="Forms.Binding"/> 实例。</returns>
 /// <exception cref="ArgumentException">给定数据为null时引发。</exception>
 /// <exception cref="ArgumentNullException">控件属性是已绑定到数据或<see cref="Forms.Binding"/> 未指定的有效列时引发。</exception>
 public IBindableProperty Binding(MultiBindableValue value, IMultiValueConverter converter, object convertParameter = null, CultureInfo culture = null)
 {
     BindingCore(value, i => converter.Convert((object[])i, bindingProperty.PropertyType, converter, culture), i => converter.ConvertBack(i, value.ValueTypes, convertParameter, culture));
     return(this);
 }
Пример #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiChained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="multiConverter">The multi-value converter.</param>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 /// <param name="converter3">The third value converter.</param>
 /// <param name="converter4">The fourth value converter.</param>
 /// <param name="converter5">The fifth value converter.</param>
 public MultiChained(IMultiValueConverter multiConverter, IValueConverter converter1, IValueConverter converter2, IValueConverter converter3, IValueConverter converter4,
                     IValueConverter converter5)
     : this(multiConverter, converter1, converter2, converter3, converter4, converter5, null, null, null)
 {
 }
Пример #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultiChained"/> class with the given instances of <see cref="IValueConverter"/>.
 /// </summary>
 /// <param name="multiConverter">The multi-value converter.</param>
 /// <param name="converter1">The first value converter.</param>
 /// <param name="converter2">The second value converter.</param>
 public MultiChained(IMultiValueConverter multiConverter, IValueConverter converter1, IValueConverter converter2)
     : this(multiConverter, converter1, converter2, null, null, null, null, null, null)
 {
 }
Пример #33
0
 public CombineMulti(IMultiValueConverter First) => this.First = First;
        internal static string BuildToolTip(ModelItem entry, IMultiValueConverter displayNameConverter, CultureInfo culture)
        {
            string result = null;
            if (null != entry && null != displayNameConverter)
            {
                StringBuilder sb = new StringBuilder();
                int indent = 0;
                ModelItem currentEntry = entry;
                while (currentEntry != null)
                {
                    if (null != currentEntry.Properties["Variables"])
                    {
                        ++indent;
                    }
                    currentEntry = currentEntry.Parent;
                }

                while (entry != null)
                {
                    if (null != entry.Properties["Variables"])
                    {
                        if (sb.Length != 0)
                        {
                            sb.Insert(0, "/");
                            sb.Insert(0, " ", --indent);
                            sb.Insert(0, Environment.NewLine);
                        }
                        var input = new object[] { entry, null != entry.Properties["DisplayName"] ? entry.Properties["DisplayName"].Value : null, (double)short.MaxValue };
                        sb.Insert(0, displayNameConverter.Convert(input, typeof(string), null, culture));
                    }
                    entry = entry.Parent;
                }
                result = sb.ToString();
            }
            return result;
        }