I’m implementing a property panel for a graph editor that I’m working on in C# WPF. The property panel for one type of object has a number of fields:
- Name
- size
- type – combobox dependent on size
- payload – combobox dependent on size and type
- tr – calculated from size, type, payload, and db values
- delay – calculated from size, tr, and db values
How should I best structure the view model such that all fields are aggressively refreshed/updated? As in if I make a change to type and/or size, tr is automatically recalculated and refreshed in the GUI. Or so on and so forth.
Do I need to rely on EventListners like PropertyChangedEvent? And how would I manage transitional states? Like if size had been set, but type hadn’t been set yet, would tr throw a nullException error that I would have to catch/ignore?
I suppose the easiest way would be to force a recalculation on all of your property setters to regenerate everything you need any time a value changes. That is, create a ViewModel that has properties for absolutely everything you want to bind to (as you normally would) and a method that recalculates everything you want to. Then in each property setter, call that method.
You could also put your recalculation method in your PropertyChanged-firing method like below, but I’m personally not a fan of that approach simply because I like OnPropertyChanged to be simiple: