Search code examples
mvvmxamarin.formsdata-binding

Xamarin.Forms data binding to object's child array


I'm creating several Editors in my codebehind and I'd like to bind their TextProperty to an object's string from an array. Object is declared inside ViewModel.

Code behind:

Editor text = new Editor();
text.SetBinding(Editor.TextProperty, "Here one string from string array in an object");

Object

public VObject {
  public string[] strings;
}

ViewModel:

public VObject CurrentObject { 
   get { return _currentObject; } 
   set 
   {
      _currentObject = value;
      OnPropertyChanged();
   } 
}

Thanks in advance for help


Solution

  • use an index to specify which array element to use

    text.SetBinding (Editor.TextProperty, "strings[0]");