Forum Xamarin.Android

Update real time data in row in listview through Xamarin Android MVVM Light

teligenz_dheerajteligenz_dheeraj Member ✭✭
edited March 28 in Xamarin.Android

I have ObservableCollection of product model objects. The model object contain name and price of product. I want to populate observablecollection in xamarin android listview. Price of product update in real time frequently from background websocket. How to bind the model product price dynamically with row textview of each cell. I am using the MVVMLight binding for this

private View GetProductRow(int position, ProductModel productModel, View productRow)
{
    View view = productRow ?? LayoutInflater.From(context).Inflate(Resource.Layout.ProductParentCell, null);
    var viewHolder = view.Tag as ProductParentHolder ?? (new ProductParentHolder(view, this, "Product"));

    viewHolder.FirstRightTV.Text = productModel.LastTradePriceString;

    viewHolder.PriceBinding = viewHolder.FirstRightTV.SetBinding(() => productViewModel.Product[position].PriceString, () => viewHolder.FirstRightTV.Text);

    view.Tag = viewHolder;

    return view;
}

Getting ERROR:
System.InvalidOperationException:

Code Line:
viewHolder.PriceBinding = viewHolder.FirstRightTV.SetBinding(() => productViewModel.Product[position].PriceString, () => viewHolder.FirstRightTV.Text);

Tagged:
Sign In or Register to comment.