Ejemplo n.º 1
0
        void OnSideChanged(PropertyPathBinding leftPropertyBinding, PropertyPathBinding rightPropertyBinding)
        {
            var result = leftPropertyBinding.TryGetValue(out var evaluatedValue);

            if (result == true)
            {
                rightPropertyBinding.TrySetValue(evaluatedValue);
            }
        }
Ejemplo n.º 2
0
        void Subscribe(PropertyPathBinding expr, PropertyPathBinding dependentExpr)
        {
            Action action = null;

            action = () =>
            {
                OnSideChanged(expr, dependentExpr);
            };

            expr.Subscribe(action);
        }
Ejemplo n.º 3
0
        public override void Unbind()
        {
            leftBinding.Unsubscribe();
            rightBinding.Unsubscribe();

            // remove all reference to left and right side to GC can collect them
            leftSide     = null;
            rightSide    = null;
            leftBinding  = null;
            rightBinding = null;

            base.Unbind();
        }
Ejemplo n.º 4
0
        public PropertyBinding(Expression leftSide, Expression rightSide, BindingDirection bindingDirection)
        {
            ValidateExpression(leftSide);
            ValidateExpression(rightSide);

            if (((PropertyInfo)((MemberExpression)leftSide).Member).PropertyType != ((PropertyInfo)((MemberExpression)rightSide).Member).PropertyType)
            {
                throw new ArgumentException("Both properties should be the same type");
            }

            this.leftSide  = leftSide;
            this.rightSide = rightSide;

            leftBinding  = CreateBindingExpression(leftSide);
            rightBinding = CreateBindingExpression(rightSide);

            if (bindingDirection == BindingDirection.RightToLeft)
            {
                var result = rightBinding.TryGetValue(out var value);

                bool leftSet = false;
                if (result == true)
                {
                    leftSet = leftBinding.TrySetValue(value);
                }
            }
            else
            {
                var result = leftBinding.TryGetValue(out var value);

                if (result == true)
                {
                    rightBinding.TrySetValue(value);
                }
            }

            Subscribe(this.leftBinding, this.rightBinding);
            Subscribe(this.rightBinding, this.leftBinding);
        }