コード例 #1
0
ファイル: FullBinding.cs プロジェクト: MKuckert/bindings
        private void CreateSourceBinding(object source)
        {
            // NOTE: We do not call the setter for DataContext here because we are
            // setting up the sourceStep.
            // If that method is updated we will need to make sure that this method
            // does the right thing.
            _dataContext            = source;
            _sourceStep             = SourceStepFactory.Create(_bindingDescription.Source);
            _sourceStep.TargetType  = _targetBinding.TargetType;
            _sourceStep.DataContext = source;

            if (NeedToObserveSourceChanges)
            {
                _sourceBindingOnChanged = (sender, args) =>
                {
                    //Capture the cancel token first
                    var cancel = _cancelSource.Token;
                    //GetValue can now be executed in a worker thread. Is it the responsibility of the caller to switch threads, or ours ?
                    //As the source is the viewmodel, i suppose it is the responsibility of the caller.
                    var value = _sourceStep.GetValue();
                    UpdateTargetFromSource(value, cancel);
                };
                _sourceStep.Changed += _sourceBindingOnChanged;
            }

            UpdateTargetOnBind();
        }
コード例 #2
0
        private bool TryEvaluateif(ISourceStep testStep, ISourceStep ifStep, ISourceStep elseStep, out object value)
        {
            var result = testStep.GetValue();

            if (result == BindingConstant.DoNothing)
            {
                value = BindingConstant.DoNothing;
                return(true);
            }

            if (result == BindingConstant.UnsetValue)
            {
                value = BindingConstant.UnsetValue;
                return(true);
            }

            if (IsTrue(result))
            {
                value = ReturnSubStepResult(ifStep);
                return(true);
            }

            value = ReturnSubStepResult(elseStep);
            return(true);
        }
コード例 #3
0
 protected virtual object ReturnSubStepResult(ISourceStep subStep)
 {
     if (subStep == null)
     {
         return(BindingConstant.UnsetValue);
     }
     return(subStep.GetValue());
 }
コード例 #4
0
ファイル: FullBinding.cs プロジェクト: MKuckert/bindings
        protected virtual void ClearSourceBinding()
        {
            if (_sourceStep != null)
            {
                if (_sourceBindingOnChanged != null)
                {
                    _sourceStep.Changed    -= _sourceBindingOnChanged;
                    _sourceBindingOnChanged = null;
                }

                _sourceStep.Dispose();
                _sourceStep = null;
            }
        }