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