Custom BindingEngine that support all .net environment : Winform, WPF, Web, Mono, Xamarin. etc.
The goal of BindingEngine is making your ViewModel everywhere.

Mark : Fully Refactor and Add Unit Test, will add the detail documentation later.

The original implementation of Winform binding is heavy and not powerful enough than WPF.
It does not support ICommand, Recursive Binding, etc.

Analyze the binding:

1. When
What trigger the binding update? Usually the binding is updated via INotifyPropertyChanged's PropertyChanged event in ViewModel scenario.
2. Direction
Direction of the Data Flow. OneWay, TwoWay, OneWayToSource, OneTime?
3. Update
After binding is triggered, the detail update strategy for different binding. The binding can work on pure Property, Collection, ICommand and Method.

The use of BindingEngine:

BindingEngine.SetXXXBinding( source, sourceProp, target, targetProp )

, XXX can be Property, Collection, Command and Method.
BindingEngine.SetPropertyBinding(nameTextbox, i => i.Text, DataWarehouse.Instance, o => o.MainViewModel.CurrentPerson.Name)    

SetPropertyBinding indicates it's a Property Binding;
SetMode indicates it's a TwoWay binding;
AttactSourceEvent indicates the binding is triggered when TextChanged event occured on the source-->nameTextbox.

BindingEngine.SetMethodBinding(viewModelLabel, i => i.Text, DataWarehouse.Instance, o => o.MainViewModel)    
             .AttachTargetMethod(o => o.MainViewModel, "GetHashCode");

This binding means the Label-->viewModelLabel.Text is bind to the MainViewModel GetHashCode method.

Have fun with it. ^_^

Last edited Nov 22, 2014 at 6:05 AM by zhouyongh, version 4