title: Binding a property to a ViewModel with MvvmLight and Xamarin.iOS
body: <p>I've used MvvmLight for a long time now which fits perfectly my needs for my Windows and Windows Phone developments, but I struggle with the new Xamarin.iOS binding features introduced in version 5.</p>
  
  <p>I've checked the <code>Flowers</code> sample, and tried to create a really simple binding that  doesn't work as expected : the update action is executed only once ...</p>
  
  <p>Here the code of the view controller :</p>
  
  <pre><code> public partial class MainViewController : UIViewController
  {
      private MainViewModel ViewModel { get; set; }
  
      public MainViewController()
          : base("MainViewController", null)
      {
          this.ViewModel = new MainViewModel();
      }
  
      public override void ViewDidLoad()
      {
          base.ViewDidLoad();
  
          this.SetBinding(() =&gt; this.ViewModel.IsUpdated).WhenSourceChanges(() =&gt;
              {
                  this.updateLabel.Text = this.ViewModel.IsUpdated ? "It's okay !" : "Nope ...";
              });
  
          this.updateButton.SetCommand("TouchUpInside", this.ViewModel.UpdateCommand);
  
      }
  }
  </code></pre>
  
  <p>The generated partial class declaration with two interface elements:</p>
  
  <pre><code>[Register ("MainViewController")]
  partial class MainViewController
  {
      [Outlet]
      MonoTouch.UIKit.UIButton updateButton { get; set; }
  
      [Outlet]
      MonoTouch.UIKit.UILabel updateLabel { get; set; }
  
      void ReleaseDesignerOutlets ()
      {
          if (updateLabel != null) {
              updateLabel.Dispose ();
              updateLabel = null;
          }
  
          if (updateButton != null) {
              updateButton.Dispose ();
              updateButton = null;
          }
      }
  }
  </code></pre>
  
  <p>And the associated ViewModel :</p>
  
  <pre><code>public class MainViewModel : ViewModelBase
  {
      public MainViewModel()
      {
          this.UpdateCommand = new RelayCommand(() =&gt;
              {
                  this.IsUpdated = !this.IsUpdated;
              });
      }
  
      private bool isUpdated;
  
      public bool IsUpdated
      {
          get { return this.isUpdated; }
          set
          {
              this.Set&lt;bool&gt;(ref this.isUpdated, value);
          }
      }
  
      public RelayCommand UpdateCommand { get; private set; }
  }
  </code></pre>
  
  <p>Anybody have a working example, and some explanations ?</p>