Ejemplo n.º 1
0
 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));
         }
     }
 }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public MVVMSetter(MVVMBinding property, object value)
 {
     Type               = MVVMSetterType.Value;
     Property           = property;
     Value              = value;
     Property.IsTrigger = true;
 }
Ejemplo n.º 5
0
 protected MVVMBinding GetBinding(ref MVVMBinding binding, Action <MVVMBinding> setBinding)
 {
     if (binding == null)
     {
         setBinding(new MVVMBinding(string.Empty));
     }
     return(binding);
 }
Ejemplo n.º 6
0
 public MVVMSetter(MVVMBinding property, MVVMBinding value)
 {
     Type                   = MVVMSetterType.Binding;
     Property               = property;
     BindingValue           = value;
     Property.IsTrigger     = true;
     BindingValue.IsTrigger = true;
 }
Ejemplo n.º 7
0
 public MVVMTrigger(MVVMBinding property, Predicate <object> predicate)
 {
     Type                      = MVVMTriggerType.Predicate;
     Property                  = property;
     Predicate                 = predicate;
     Property.IsTrigger        = true;
     Property.OnSetTargetValue = OnSetTargetValue;
 }
Ejemplo n.º 8
0
 public MVVMTrigger(MVVMBinding property, object value)
 {
     Type                      = MVVMTriggerType.Value;
     Property                  = property;
     Value                     = value;
     Property.IsTrigger        = true;
     Property.OnSetTargetValue = OnSetTargetValue;
 }
Ejemplo n.º 9
0
 public MVVMTrigger(MVVMBinding property, MVVMBinding bindingValue)
 {
     Type                      = MVVMTriggerType.Binding;
     Property                  = property;
     BindingValue              = bindingValue;
     Property.IsTrigger        = true;
     BindingValue.IsTrigger    = true;
     Property.OnSetTargetValue = OnSetTargetValue;
 }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
 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();
             }
         }
     };
 }
Ejemplo n.º 12
0
 protected override void OnSetText(MVVMBinding text)
 {
     text.DefaultMode = MVVMBindingMode.TwoWay;
     text.DefaultUpdateSourceTrigger = MVVMUpdateSourceTrigger.PropertyChanged;
 }
Ejemplo n.º 13
0
 public MVVMSetter(string property, MVVMBinding value) : this(new MVVMBinding(new MVVMRelativeSource(), property), value)
 {
 }
Ejemplo n.º 14
0
 public MVVMTrigger(string property, MVVMBinding bindingValue) : this(new MVVMBinding(new MVVMRelativeSource(), property), bindingValue)
 {
 }
Ejemplo n.º 15
0
 protected virtual void OnSetText(MVVMBinding text)
 {
 }
Ejemplo n.º 16
0
 protected override void OnSetText(MVVMBinding text)
 {
     text.DefaultMode = MVVMBindingMode.TwoWay;
 }