protected void AddToTrackerHandler <TResult>(IBinder sender, BinderValueChangedArgs <TResult> args)
        {
            if (_isInUndoProcess || _isInRedoProcess)    //ignore changes stated by Undo/Redo
            {
                return;
            }

            if (_binderTrackerPosition > -1 && _binderTrackerPosition < _bindersTracker.Count - 1)
            {
                _bindersTracker = _bindersTracker.Splice(_binderTrackerPosition);
            }

            var addNewBindTracker = true;

            if (_bindersTracker.Count > 0)
            {
                var last = _bindersTracker[_bindersTracker.Count - 1];
                if (last.Binder.Equals(sender)) //if last binder is the same with the current binder
                {
                    last.Value        = args.Value;
                    addNewBindTracker = false;
                }
            }
            if (addNewBindTracker)
            {
                _bindersTracker.Add(new BinderTrackerValue(sender, args.Value));
                _binderTrackerPosition++;
            }
        }
示例#2
0
        /// <summary>
        /// Set value to the property of the bounded entity
        /// </summary>
        /// <param name="value">New value</param>
        protected virtual void BindValueToProperty(TResult value)
        {
            if (InternalSet)
            {
                return;
            }

            var entity = _entity();

            //                      if validators will permit
            if (entity != null && (Validators?.All(v => v.IsValid(value)) ?? true))
            {
                ReflexionEx.SetPropertyValue(entity, value, _result);

                if (OnChanged != null)
                {
                    var property = ReflexionEx.GetPropertyInfo(_result);
                    var args     = new BinderValueChangedArgs <TResult>(value, property.Name);
                    OnChanged?.Invoke(this, args);
                }
            }
        }