DelayBind什么时候用?

DelayBind when to use?

我不明白 DelayBind 函数的用例是什么。我可以简单地使用

var set = this.CreateBindingSet<Activity, ViewModel();

但是为什么以及什么时候应该使用

this.DelayBind(() => { var set = this.CreateBindingSet<Activity, ViewModel() }

?

DelayBind 当您希望每次 DataContext 更改时都应用绑定,如您所见 here。主要用途是绑定列表项,例如 MvxTableViewCell 因为它知道 何时 应该应用它的绑定,并且 "refreshed" 例如:

public partial class MonkeyCell : MvxTableViewCell
{
    public static readonly NSString Key = new NSString("MonkeyCell");
    public static readonly UINib Nib;

    static MonkeyCell()
    {
        Nib = UINib.FromName("MonkeyCell", NSBundle.MainBundle);
    }

    protected MonkeyCell(IntPtr handle) : base(handle)
    {

        var imageViewLoader = new MvxImageViewLoader(() => monkeyImage);

        // Note: this .ctor should not contain any initialization logic.
        this.DelayBind(() =>
        {
            var set = this.CreateBindingSet<MonkeyCell, Monkey>();
            set.Bind(imageViewLoader).To(m => m.Image);
            set.Bind(nameLabel).To(m => m.Name);
            set.Bind(originLabel).To(m => m.Location);
            set.Bind(descriptionLabel).To(m => m.Details);
            set.Apply();
        });
    }
}

来源和完整示例:Binding lists with iOS and MvvmCross