【问题标题】:Xamarin.Forms data binding to object's child arrayXamarin.Forms 数据绑定到对象的子数组
【发布时间】:2020-04-20 20:07:56
【问题描述】:

我在我的代码隐藏中创建了几个编辑器,我想将它们的 TextProperty 绑定到数组中的对象字符串。对象在 ViewModel 中声明。

后面的代码:

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

对象

public VObject {
  public string[] strings;
}

视图模型:

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

提前感谢您的帮助

【问题讨论】:

    标签: mvvm xamarin.forms data-binding


    【解决方案1】:

    使用索引指定要使用的数组元素

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

    【讨论】:

    • 感谢您的回复!我想知道如何从代码隐藏中访问 CurrentObject?
    • text.SetBinding (Editor.TextProperty, "CurrentObject.strings[0]");会好吗?
    • 如果这是 ViewModel 的属性,那么是的
    • 我收到一个错误:System.Reflection.TargetParameterCountException: '指定的参数数量与预期数量不匹配。'
    • 一切都如你所写,问题出在我的代码中。非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2016-09-30
    • 2016-09-25
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    相关资源
    最近更新 更多