Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DelayBind when to use?

I don't understand what is a usecase for DelayBind function. I can simply use

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

but why and when I should use

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

?

like image 218
qwertylolman Avatar asked Dec 12 '25 09:12

qwertylolman


1 Answers

DelayBind is used when you want the bindings to be applied every time the DataContext changes as you can see here. The mainly use is to bind list items such as a MvxTableViewCell because it knows when its binding should be applied and "refreshed" e.g.:

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();
        });
    }
}

Source and the full example: Binding lists with iOS and MvvmCross

like image 193
fmaccaroni Avatar answered Dec 15 '25 22:12

fmaccaroni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!