public override Action Bind(object control, INotifyPropertyChanged model) { var controlPropertyInfo = control.GetType().GetProperty(this.ControlPropertyName); var modelPropertyInfo = model.GetType().GetProperty(this.ModelPropertyName); var forwardBinding = new BindingClosure(() => this.TransferValue(BindingDirection.Forward, model, control, modelPropertyInfo, controlPropertyInfo, this.ModelPropertyIndex, this.ControlPropertyIndex)); forwardBinding.Execute(); var unregisterForwardBinding = this.RegisterForwardBinding(model, forwardBinding); return(unregisterForwardBinding); }
public override Action Bind(object control, INotifyPropertyChanged model) { var modelPropertyInfo = model.GetType().GetProperty(this.ModelPropertyName); var commandBinding = new BindingClosure(() => this.ExecuteCommand(model, modelPropertyInfo)); var unregisterReverseBinding = this.RegisterReverseBinding(control, commandBinding); return(() => { unregisterReverseBinding.Invoke(); unregisterReverseBinding = null; }); }
protected Action RegisterReverseBinding(object control, BindingClosure applyReverseBindingOnce) { var changeEventInfo = control.GetType().GetEvent(this.ControlEventName); var handler = Delegate.CreateDelegate(changeEventInfo.EventHandlerType, applyReverseBindingOnce, applyReverseBindingOnce.MethodInfo); changeEventInfo.AddEventHandler(control, handler); return(() => { changeEventInfo.RemoveEventHandler(control, handler); handler = null; }); }
public override Action Bind(object control, INotifyPropertyChanged model) { var controlPropertyInfo = control.GetType().GetProperty(this.ControlPropertyName); var modelPropertyInfo = model.GetType().GetProperty(this.ModelPropertyName); var reverseBinding = new BindingClosure(() => this.TransferValue(BindingDirection.Reverse, control, model, controlPropertyInfo, modelPropertyInfo, this.ControlPropertyIndex, this.ModelPropertyIndex)); reverseBinding.Execute(); var unregisterReverseBinding = this.RegisterReverseBinding(control, reverseBinding); return(() => { unregisterReverseBinding.Invoke(); unregisterReverseBinding = null; }); }
protected Action RegisterForwardBinding(INotifyPropertyChanged model, BindingClosure applyBindingOnce) { PropertyChangedEventHandler handler = (sender, e) => { if (e.PropertyName == this.ModelPropertyName) { applyBindingOnce.Execute(); } }; model.PropertyChanged += handler; return(() => { model.PropertyChanged -= handler; handler = null; }); }