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 void CreateSourceBinding(object source) { _dataContext = source; _sourceStep = SourceStepFactory.Create(_bindingDescription.Source); _sourceStep.TargetType = _targetBinding.TargetType; _sourceStep.DataContext = source; if (NeedToObserveSourceChanges) { _sourceBindingOnChanged = (sender, args) => { var value = _sourceStep.GetValue(); UpdateTargetFromSource(value); }; _sourceStep.Changed += _sourceBindingOnChanged; } UpdateTargetOnBind(); }