我不明白 DelayBind 函数的用例是什么。我可以简单地使用
var set = this.CreateBindingSet<Activity, ViewModel();
但是为什么以及何时应该使用
this.DelayBind(() => { var set = this.CreateBindingSet<Activity, ViewModel() }
?
最佳答案
DelayBind
用于当您希望每次 DataContext 更改时都应用绑定(bind),如您所见 here .主要用于绑定(bind)列表项,例如 MvxTableViewCell
,因为它知道何时应该应用其绑定(bind)并且 “刷新” 例如:
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();
});
}
}
关于xamarin - DelayBind什么时候用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092429/