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(); }
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); }
protected virtual object ReturnSubStepResult(ISourceStep subStep) { if (subStep == null) { return(BindingConstant.UnsetValue); } return(subStep.GetValue()); }
private void UpdateTargetOnBind() { if (NeedToUpdateTargetOnBind && _sourceStep != null) { _cancelSource.Cancel(); _cancelSource = new CancellationTokenSource(); var cancel = _cancelSource.Token; try { var currentValue = _sourceStep.GetValue(); UpdateTargetFromSource(currentValue, cancel); } catch (Exception exception) { Log.Trace("Exception masked in UpdateTargetOnBind {0}", exception); } } }