xamarin - DelayBind什么时候用?

标签 xamarin xamarin.ios xamarin.android mvvmcross

我不明白 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();
        });
    }
}

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

关于xamarin - DelayBind什么时候用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092429/

相关文章:

android - 访问路径 resources.apk.bk 被拒绝

ios - 从没有 xcworkspace 的 .APP 包构建 IPA

xamarin - 命名空间和智能感知在 Xamarin Forms 的 droid 项目中不起作用

ios - 更新到 Xamarin touch 8.2 并使用 mvvmcross

ios - 为什么我在 Xamarin iOS 中收到 "Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES"错误?

ios - 弹跳式动画。当您将其应用于同一属性(property)时

android - 无法使用 Android 支持库 v4

Xamarin Android Profiler 无法启动 — "Deploy your app again with a newer version of Xamarin Studio"

visual-studio - 如何在 Visual Studio 中将构建配置更改为发布?

mvvm - 是否可以使用 Fluent API 在 mvvmcross 中进行方法绑定(bind)?