property engine precedence (part 3)

Invalidation and PropertyChangedCallback

Whenever something happens that causes the property engine to reevaluate properties, we say that DependencyObject/property combination has been invalidated. Invalidations happen for a variety of reasons, including SetValue, triggers taking effect, animations ticking off, and tree changes (e.g., element added or removed from the tree).

 

During invalidation, the property engine will walk around the tree, recalculating values, firing PropertyChangedCallbacks if the new value is different from the old, and invalidating other DependencyObject/property combinations.

 

The order in which invalidation is done is undefined. PropertyChangedCallback can be called before all properties have been invalidated. If from inside PropertyChangedCallback you retrieve the value of a different DO/DP combination, it may not be correct yet because that DO/DP may not have been invalidated yet. One approach is if your calculation depends on multiple properties, then listen to changes on all the relevant properties.

 

If an unhandled exception is thrown inside PropertyChangedCallback, invalidation will stop and the property engine will be left in a weird, inconsistent state.