Say I have a view model which has price and quantity properties in a view model implementing INotifyPropertyChanged
which are bound to text boxes and total cost property which is bound to a text block. When either the price or the quantity is updated the total cost should be recalculated.
I understand that it desirable to minimize the amount of work that is done inside property setters and getters. Is it bad practice to trigger the calculation from setters of the properties? If it is bad practice how else should I do it? I can see two possibilities.
Subscribe to the PropertyChanged event and trigger the calculation from there. I feel this event is more for outside observers than for use in the view model itself, and in any case any the event is triggered from the setter so I don't see how it is much different from triggering the processing from setter directly.
Trigger the calculation from an event on the text box (say LostFocus) the property is bound to either by directly calling a method on the view model from the event or by binding the event to a command on the view model. It seems to me that with MVVM the idea is that we should avoid using control events if possible.