public static void UpdateSourceValue <TRoot, TSource, TSourceValue, TTarget, TTargetValue>(
            ITwoWayBindingControl <TSourceValue, TTargetValue> bindingControl,
            ref DataBindingState <TRoot, TSource, TSourceValue, TTarget, TTargetValue> dataBindingState,
            Action <TSource, TSourceValue> setSourceValue)
            where TTarget : DependencyObject
        {
            if (dataBindingState.IsUpdating)
            {
                return;
            }

            var source = dataBindingState.BindingContext.Source;

            if (source != null)
            {
                var target = dataBindingState.Target;
                if (target != null)
                {
                    var targetValue = dataBindingState.GetTargetValue(target);
                    var sourceValue = dataBindingState.ConversionParameters.ValueConverter != null
                        ? dataBindingState.ConversionParameters.ValueConverter.ConvertBack(
                        targetValue,
                        typeof(TSourceValue),
                        dataBindingState.ConversionParameters.ConverterParameter,
#if WINDOWS_UWP
                        (string)target.GetValue(FrameworkElement.LanguageProperty))
#else
                        ((XmlLanguage)target.GetValue(FrameworkElement.LanguageProperty)).GetSpecificCulture())
#endif
                        : bindingControl.GetSourceValue(targetValue);

                    /*if (!Equals(sourceValue, dataBindingState.CurrentSourceValue))
                     * {*/
                    dataBindingState.IsUpdating = true;
                    //// dataBindingState.CurrentSourceValue = sourceValue;
                    setSourceValue(source, sourceValue);
                    dataBindingState.IsUpdating = false;
                    //// }
                }
            }

            dataBindingState.CurrentSource = source;
        }
예제 #2
0
        /// <summary>Initializes a new instance of the <see cref="DataBinding{TRoot, TSource,TSourceValue,TTarget,TTargetValue}"/> class.</summary>
        /// <param name="id">The id.</param>
        /// <param name="bindingContext">The data context.</param>
        /// <param name="target">The target.</param>
        /// <param name="sourceProperty">The source property.</param>
        /// <param name="getSourceValue">The get source value.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="getTargetValue">The get target value.</param>
        /// <param name="setSource">The set source.</param>
        /// <param name="updateSourceTrigger">The update source trigger value.</param>
        /// <param name="bindingMode">The binding mode value.</param>
        public DataBinding(
            int id,
            IBindingContext <TRoot, TSource> bindingContext,
            TTarget target,
            INotifyingProperty <TSource> sourceProperty,
            Func <TSource, TSourceValue> getSourceValue,
            DependencyProperty targetProperty,
            Func <TTarget, TTargetValue> getTargetValue,
            Action <TSource, TSourceValue> setSource,
            UpdateSourceTrigger updateSourceTrigger,
            BindingMode bindingMode)
        {
            this.sourceProperty = sourceProperty;
            this.setSource      = setSource;
            DataBindingHelper.GetNotificationParameters(target, targetProperty, ref bindingMode, ref updateSourceTrigger);
            DataBindingHelper.TryRegisterLostFocus(target, updateSourceTrigger, this.OnTargetLostFocus);
            var conversionParameters = ConversionProvider.GetConversionParameters <TSourceValue, TTargetValue>(target, id, bindingMode);

            this.dataBindingState = new DataBindingState <TRoot, TSource, TSourceValue, TTarget, TTargetValue>(bindingContext, target, targetProperty, getTargetValue, getSourceValue, bindingMode, updateSourceTrigger, conversionParameters);
            this.sourceProperty.Initialize(this);
        }
        /// <summary>Initializes a new instance of the <see cref="DataBindingOneWay{TRoot,TSource,TTarget,TValue}"/> class.</summary>
        /// <param name="id">The id.</param>
        /// <param name="bindingContext">The data context.</param>
        /// <param name="target">The  target.</param>
        /// <param name="sourceProperty">The source property.</param>
        /// <param name="getSourceValue">The get source value.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="getTargetValue">The get target value.</param>
        /// <param name="bindingMode">The binding mode value.</param>
        public DataBindingOneWay(
            int id,
            IBindingContext <TRoot, TSource> bindingContext,
            TTarget target,
            INotifyingProperty <TSource> sourceProperty,
            Func <TSource, TValue> getSourceValue,
            DependencyProperty targetProperty,
            Func <TTarget, TValue> getTargetValue,
            BindingMode bindingMode)
        {
            this.sourceProperty = sourceProperty;
            var conversionParameters = ConversionProvider.GetConversionParameters <TValue, TValue>(target, id);

            this.dataBindingState = new DataBindingState <TRoot, TSource, TValue, TTarget, TValue>(
                bindingContext,
                target,
                targetProperty,
                getTargetValue,
                getSourceValue,
                bindingMode,
                UpdateSourceTrigger.Explicit,
                conversionParameters);
            this.sourceProperty.Initialize(this);
        }