I have a WPF DataGrid displaying Products. I have two fields price and mass in that which are actually the properties of Product class. I need to show a seperate column in grid name MultipliedValue = price * mass. As per MVVM model where should i do it ?
1) In model by making a readonly property.
2) In converter so that only my UI will be aware of that?
3) or in View model?
Please suggest which option i should choose and why?
Thanks.
I would disregard option #2 from the beginning — converters should be used only to account for implementation details of the UI, and specifically in MVVM perhaps not even then (as you can do the conversion inside the ViewModel, which is option #3 and more convenient).
Between #1 and #3, in this case IMHO it’s best to go with #1 — price is not something that’s only relevant for your UI and of course the concept of price (and how it is derived) is going to stay fixed throughout your application. Both the UI and your backend may choose to use this property or not.