Tuesday, August 05, 2014

Auto binding of outlets in Xamarin iOS and MvvmCross

 

If you are like me and you don’t like doing the bindings in code, you start thinking about solutions.

So I’m experimenting with the idea of creating the bindings at runtime, based on a simple name convention:

  • An UIButton outlet with the name 'btnXXX' is bound to the view-model 'XXXCommand' property.
  • An UITextField outlet with the name 'txtXXX' is bound to the view-model 'XXX' property.
  • An UILabel outlet with the name 'lblXXX' is bound to the view-model 'XXX' property.

For example, if you have a UIButton outlet called btnLogin, it's bound to view-model LoginCommand property.

I uploaded the code here;

https://github.com/nitescua/AutoBinding/

This can be done for other platforms as well.