I have made a control which has a property that is calculated by using a few other properties as input. When any of these input properties change, the property needs to be updated. I already have made this possible through implementing property-changed events for them, marking the dependent property as updated. Changing 3 properties means 3 property refreshes.
The problem I am experiencing is that when more than one of these properties change, the dependency property is updated each time any of these properties is changed. The property however takes some time to calculate (and/or render). When more than one property is going to be changed, I would like to let it update only once, after I have updated all the properties.
Goal: The control needs to be updated only when the program is done changing all the properties.
What I have tried:
- Make the property lazy by only updating it when requested. (Does not work, WPF requests it anyway);
- Cache the result of the calculation. (Does not work because there is always 1 input changed, making the cache invalid);
- Make a method to set multiple properties at once. (Does not work, some properties are inherited and come from another control);
- Make the control collapsed before manipulating the properties. (Does not work, WPF still refreshes the properties).
Does anybody have a better solution?
You can postpone raising the property changed event. Or create a method that will stop propagating this event (i.e.
StartUpdating) and another method that will fire all the events (i.e.EndUpdating).and in your methods