private bool TryEvaluateif(IMvxSourceStep testStep, IMvxSourceStep ifStep, IMvxSourceStep elseStep, out object value) { var result = testStep.GetValue(); if (result == MvxBindingConstant.DoNothing) { value = MvxBindingConstant.DoNothing; return(true); } if (result == MvxBindingConstant.UnsetValue) { value = MvxBindingConstant.UnsetValue; return(true); } if (IsTrue(result)) { value = ReturnSubStepResult(ifStep); return(true); } value = ReturnSubStepResult(elseStep); return(true); }
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(); }
protected virtual object ReturnSubStepResult(IMvxSourceStep subStep) { if (subStep == null) { return(MvxBindingConstant.UnsetValue); } return(subStep.GetValue()); }
protected virtual object ReturnSubStepResult(IMvxSourceStep subStep) { if (subStep == null) { return MvxBindingConstant.UnsetValue; } return subStep.GetValue(); }
private void UpdateTargetOnBind() { if (NeedToUpdateTargetOnBind && _sourceStep != null) { // note that we expect Bind to be called on the UI thread - so no need to use RunOnUIThread here try { var currentValue = _sourceStep.GetValue(); UpdateTargetFromSource(currentValue); } catch (Exception exception) { MvxBindingTrace.Trace("Exception masked in UpdateTargetOnBind {0}", exception.ToLongString()); } } }
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) { MvxBindingLog.Trace("Exception masked in UpdateTargetOnBind {0}", exception.ToLongString()); } } }
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(); }
private bool TryEvaluateIf(IMvxSourceStep testStep, IMvxSourceStep ifStep, IMvxSourceStep elseStep, out object value) { var result = testStep.GetValue(); if (result == MvxBindingConstant.DoNothing) { value = MvxBindingConstant.DoNothing; return true; } if (result == MvxBindingConstant.UnsetValue) { value = MvxBindingConstant.UnsetValue; return true; } if (IsTrue(result)) { value = ReturnSubStepResult(ifStep); return true; } value = ReturnSubStepResult(elseStep); return true; }