How to binding textview in a listview at runtime with MVVMLight

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

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!
Coordinator
Jun 27 at 7:57 PM
Hi.

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

See my Xamarin Evolve presentation and the corresponding code sample.
http://www.galasoft.ch/presentations/presentationdetails.cshtml?name=2016006

Thanks
Laurent
Jun 28 at 2:47 AM
Edited Jun 28 at 3: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.

Hoangwy
Thanks
Coordinator
Jun 28 at 4:41 AM
Hi,

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
Laurent
Jun 28 at 6:51 AM
Hi Laurent,

Could you can make a simple example about this?

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

What you want is this:
https://github.com/lbugnion/sample-evolve-2016/blob/master/XamBindingSample/XamBindingSample.Droid/ListsActivity.cs

Lines 83 and below.

Thanks
Laurent
Jun 30 at 3:14 AM
Hi Ibugnion,

Can I use Fragment with MVVMLight?

Thanks!
hoangwy