Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Bind a function on an item of a ListView

$
0
0

This is my starting point:

  • a DataModel Product which has some parameters like quantity, cost, type
  • a ViewModel which loads a list of products
  • a ContentPage which show the products in a ListView, the BindingContext is the ViewModel above

For each product I would like to show some fields like name, quantity, cost... and a calculated field which multiply quantity and cost, but also could have additional logic based on type or user parameters.
I could easily add a new field with only a getter "CalculatedCost" in the Product DataModel, but I don't like very much this, because I'd prefer keep the logic of this calculation outside.

The second idea is to create a static Converter to calculate this, but as far as I now, I could only pass a specific parameter to the converter, while I should make a calculation on the whole model, so how could I pass the whole object from the ListView item?
{Binding ??, Converter={StaticResource costCalculationConverter}}

Third idea, could I call a function of the ViewModel, passing the current Product in the list?

Any other idea to achieve this?
Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>