예제 #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;
 }