#165 – Overriding Metadata Can Result in Merged Metadata
December 24, 2010 Leave a comment
If you override metadata for a dependency property that a class inherits from its parent, you can specify one or more things to override:
- The default value
- The PropertyChangedCallback
- The CoerceValueCallback
- Other flags specified for UIPropertyMetadata or FrameworkPropertyMetadata
If you don’t specify all of these things, however, the items that you do not specify will be inherited from the parent.
For example, we created a child class of Slider and overrode metadata to provide a new default value for the Maximum property. But the coercion behavior of Maximum in our new class behaves as it does for Slider.Maximum. (Maximum can’t be set below Minimum).
Because we didn’t specify a CoerceValueCallback, the existing coercion logic is used.
When you do specify new metadata:
- New default value replaces the existing one
- PropertyChangedCallback is merged with the existing one (both are invoked)
- CoerceValueCallback replaces the existing one