Exemplo n.º 1
0
        public void Activate(IBindingContainer bindingContainer, PropertyExpression targetPropertyExpression)
        {
            if (bindingContainer == null)
            {
                throw new ArgumentNullException("bindingContainer");
            }
            if (!bindingContainer.Bindings.Contains(this))
            {
                throw new InvalidOperationException(Resources.BindingMustBeActivatedInOwningContainer);
            }

            if (Interlocked.CompareExchange(ref _activated, 1, 0) != 0)
            {
                throw new InvalidOperationException(Resources.AlreadyActivated);
            }

            _container = bindingContainer;
            _targetPropertyExpression = targetPropertyExpression;

            if (TargetPropertyExpression == null)
            {
                //no target property expression was provided when activating, so ask the base class to create one
                TargetPropertyExpression = AttemptCreateTargetPropertyExpression();
            }

            if (TargetPropertyExpression != null && (Mode == BindingMode.TwoWay || Mode == BindingMode.OneWayToSource))
            {
                //listen for changes in the target
                TargetPropertyExpression.ValueChanged += TargetPropertyExpressionValueChanged;
            }

            OnActivated();
        }
Exemplo n.º 2
0
        public void Activate(IBindingContainer bindingContainer, PropertyExpression targetPropertyExpression)
        {
            if (bindingContainer == null)
                throw new ArgumentNullException("bindingContainer");
            if (!bindingContainer.Bindings.Contains(this))
                throw new InvalidOperationException(Resources.BindingMustBeActivatedInOwningContainer);

            if (Interlocked.CompareExchange(ref _activated, 1, 0) != 0)
            {
                throw new InvalidOperationException(Resources.AlreadyActivated);
            }

            _container = bindingContainer;
            _targetPropertyExpression = targetPropertyExpression;

            if (TargetPropertyExpression == null)
            {
                //no target property expression was provided when activating, so ask the base class to create one
                TargetPropertyExpression = AttemptCreateTargetPropertyExpression();
            }

            if (TargetPropertyExpression != null && (Mode == BindingMode.TwoWay || Mode == BindingMode.OneWayToSource))
            {
                //listen for changes in the target
                TargetPropertyExpression.ValueChanged += TargetPropertyExpressionValueChanged;
            }

            OnActivated();
        }