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