This project has moved and is read-only. For the latest updates, please go here.

How to binding textview in a listview at runtime with MVVMLight

Jun 27, 2016 at 8:49 AM
Edited Jun 27, 2016 at 8:50 AM
This is my model:
int amount;
    public int Amount
        get { return amount; }
            if(Set(() => Amount, ref amount, value));
When I click on button Amount will plus 1:

var tvAmount = convertView.FindViewById(Resource.Id.tvAmount);
tvAmount.Text = viewModel.Model.Amount;
But UI not update. When I scroll listview. UI changed

I want to TextView change when I click. Please help me!
Thank so much!
Jun 27, 2016 at 8:57 PM

You need to set a binding between Amount and the TextView.

See my Xamarin Evolve presentation and the corresponding code sample.

Jun 28, 2016 at 3:47 AM
Edited Jun 28, 2016 at 4:06 AM
System.InvalidOperationException: Are you trying to use SetBinding with a local variable? Try to use new Binding instead
            tvAmount.SetBinding(() => viewModel.Model.AmountFormatted, () => tvAmount.Text);
When I binding, I got an exception.

Jun 28, 2016 at 5:41 AM

Again, please check the code sample from my Xamarin Evolve talk. There is a similar sample there. Also, read the text of the error. You cannot use the SetBinding method with local variables. You need to use new Binding() instead.

Thank you
Jun 28, 2016 at 7:51 AM
Hi Laurent,

Could you can make a simple example about this?

Thanks so much!
Jun 28, 2016 at 8:36 AM
I Found an example, thank Laurent <3
Jun 28, 2016 at 8:43 AM
OK, just to be sure we talk about the same:

What you want is this:

Lines 83 and below.

Jun 30, 2016 at 4:14 AM
Hi Ibugnion,

Can I use Fragment with MVVMLight?