public void SetSourceValue(object value) { if (BlockSetSourceValue) { return; } SourceValue = value; if (SourcePropertyName == null || !PropertyInfo.CanWrite) { return; } if (ValidatesOnExceptions) { Control.Validation.Clear(); } try { if (PropertyInfo.PropertyType == typeof(MVVMBinding)) { MVVMBinding binding = PropertyInfo.GetValue(Instance, null) as MVVMBinding; if (binding != null) { binding.SetTargetValue(value); } return; } PropertyInfo.SetValue(Instance, MVVMAPI.ChangeType(value, PropertyInfo.PropertyType), null); } catch (Exception exception) { if (ValidatesOnExceptions) { Control.Validation.Add(new MVVMValidationError(exception.GetBaseException().Message, exception)); } } }
protected void SetBinding( ref MVVMBinding binding, MVVMBinding value, MVVMFunc <object> getTargetValue = null, Action <object> setTargetValue = null, bool isInteractive = false, bool isText = false, bool isDataContext = false, MVVMAction unbind = null, [CallerMemberName] string propertyName = null ) { if (!isDataContext && binding != null) { Bindings.Remove(binding); } binding = value; if (binding == null) { return; } binding.Control = this; if (propertyName == null) { propertyName = MVVMAPI.GetCallerMemberName(); } binding.TargetPropertyName = propertyName; binding.IsDataContext = isDataContext; binding.OnGetTargetValue = getTargetValue; binding.OnSetTargetValue = setTargetValue; binding.OnUnbind = unbind; binding.DefaultMode = isInteractive ? MVVMBindingMode.TwoWay : MVVMBindingMode.OneWay; binding.DefaultUpdateSourceTrigger = isText ? MVVMUpdateSourceTrigger.LostFocus : MVVMUpdateSourceTrigger.PropertyChanged; if (!isDataContext) { Bindings.Add(binding); } }
internal protected void OnChanged(MVVMBinding binding, MVVMOnChangedType onChangedType = MVVMOnChangedType.PropertyChanged) { if (binding == null || binding.BlockOnChanged > 0 || binding.IsTrigger) { return; } switch (binding.GetMode()) { case MVVMBindingMode.TwoWay: case MVVMBindingMode.OneWayToSource: switch (binding.GetUpdateSourceTrigger()) { case MVVMUpdateSourceTrigger.PropertyChanged: if (onChangedType == MVVMOnChangedType.PropertyChanged) { binding.OneWaySetSourceValue(); } break; case MVVMUpdateSourceTrigger.LostFocus: if (onChangedType == MVVMOnChangedType.LostFocus) { binding.OneWaySetSourceValue(); } break; } break; } this.RaisePropertyChanged(binding.TargetPropertyName); }
public MVVMSetter(MVVMBinding property, object value) { Type = MVVMSetterType.Value; Property = property; Value = value; Property.IsTrigger = true; }
protected MVVMBinding GetBinding(ref MVVMBinding binding, Action <MVVMBinding> setBinding) { if (binding == null) { setBinding(new MVVMBinding(string.Empty)); } return(binding); }
public MVVMSetter(MVVMBinding property, MVVMBinding value) { Type = MVVMSetterType.Binding; Property = property; BindingValue = value; Property.IsTrigger = true; BindingValue.IsTrigger = true; }
public MVVMTrigger(MVVMBinding property, Predicate <object> predicate) { Type = MVVMTriggerType.Predicate; Property = property; Predicate = predicate; Property.IsTrigger = true; Property.OnSetTargetValue = OnSetTargetValue; }
public MVVMTrigger(MVVMBinding property, object value) { Type = MVVMTriggerType.Value; Property = property; Value = value; Property.IsTrigger = true; Property.OnSetTargetValue = OnSetTargetValue; }
public MVVMTrigger(MVVMBinding property, MVVMBinding bindingValue) { Type = MVVMTriggerType.Binding; Property = property; BindingValue = bindingValue; Property.IsTrigger = true; BindingValue.IsTrigger = true; Property.OnSetTargetValue = OnSetTargetValue; }
protected void OnCommand(MVVMBinding command, MVVMBinding parameter) { if (command == null) { return; } IMVVMCommand relayCommand = command.GetTargetValue <IMVVMCommand> (); if (relayCommand == null) { return; } object value = parameter == null ? null : parameter.GetTargetValue(); if (relayCommand.CanExecute(value)) { relayCommand.Execute(value); } }
public MVVMTrigger(MVVMBinding binding, object value) { Binding = binding; Value = value; Binding.IsTrigger = true; Binding.OnSetTargetValue = targetValue => { if (Equals(targetValue, Value)) { foreach (MVVMSetter setter in Setters) { setter.Apply(); } } else { foreach (MVVMSetter setter in Setters) { setter.Restore(); } } }; }
protected override void OnSetText(MVVMBinding text) { text.DefaultMode = MVVMBindingMode.TwoWay; text.DefaultUpdateSourceTrigger = MVVMUpdateSourceTrigger.PropertyChanged; }
public MVVMSetter(string property, MVVMBinding value) : this(new MVVMBinding(new MVVMRelativeSource(), property), value) { }
public MVVMTrigger(string property, MVVMBinding bindingValue) : this(new MVVMBinding(new MVVMRelativeSource(), property), bindingValue) { }
protected virtual void OnSetText(MVVMBinding text) { }
protected override void OnSetText(MVVMBinding text) { text.DefaultMode = MVVMBindingMode.TwoWay; }