我有一个带有属性List<MyModel> Items
的视图模型。设置Items
集合后,我向iOS中的ViewController
触发了一个事件。然后ViewController
接收事件并遍历Items
以创建以编程方式构建的包含各种标签和文本字段的UI。
我想做的是将UITextField绑定到Items内MyModel上的属性,但是在MVVMCross中看不到做到这一点的方法。有什么建议么?
下面是一些简化的代码,以进一步概述我的问题:
public class MyModel : MvxNotifyPropertyChanged
{
public string SomeProperty
{
get => return this.someProperty;
set => this.SetProperty(ref this.someProperty, value);
}
}
public class MyViewModel : MvxViewModel
{
public List<MyModel> Items { get; set; }
public event EventHandler onItemsLoaded;
public void Initialize()
{
this.Items = this.someService.GetItems();
this.onItemsLoaded.Invoke(this, EventArgs.Empty);
}
}
public class MyViewController : MvxViewController<MyViewModel>
{
public override void ViewDidLoad()
{
this.ViewModel.onItemsLoaded += this.HandleItemsLoaded;
}
private void HandleItemsLoaded(object sender, EventArgs args)
{
foreach (var item in this.ViewModel.Items)
{
var textField = new UITextField();
// TODO: How to bind textField.Text to item.SomeProperty??
this.View.AddSubview(textField);
}
}
}