Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences among PropertyMetaData, UIPropertyMetadata, and FrameworkMetaData in WPF

Tags:

wpf

I know the basic difference among these classes that PropertyMetadata is used when we backup property, UIPropertyMetadata when we want to have support for animation, and FrameworkMetadata for Framework properties to be used in user controls.

But I understand theoretical part only. It will be a great hep if you please explain a simplest example that uses all these 3 classes in 3 different dependency properties distinguishing them clearly.

Thanks in advance.

like image 872
WpfBee Avatar asked Jan 08 '13 18:01

WpfBee


2 Answers

Source: PropertyMetadata vs. FrameworkPropertyMetadata

When you implement a custom dependency property and you register the property by calling DependencyProperty.Register, you specify some metadata for the property by passing it an instance of PropertyMetadata. This can be an instance of the PropertyMetadata class or an instance of one of its subclasses. The differences are shown below.

PropertyMetadata – Basic metadata relating to dependency properties

  • CoerceValueCallback – coerce the value when being set
  • DefaultValue – a default value for the property
  • PropertyChangedCallback – respond to new effective value for the property

UIPropertyMetadata – derives from PropertyMetadata and adds:

  • IsAnimationProhibited – disable animations for this property?

FrameworkPropertyMetadata – derives from UIPropertyMetadata and adds:

  • AffectsArrange, AffectsMeasure, AffectsParentArrange, AffectsParentMeasure, AffectsRender – Should layout calculations be re-run after property value changes?
  • BindsTwoWayByDefault, DefaultUpdateSourceTrigger, IsDataBindingAllowed, IsNotDataBindable – Dictates how property participates in data binding
  • Inherits, OverridesInheritanceBehavior – Does inheritance work for this property?
  • Journal – Store this value when journaling?
  • SubPropertiesDoNotAffectRender – Check properties of this object when layout changes?
like image 155
Muthuganesh Avatar answered Nov 08 '22 14:11

Muthuganesh


An important practical difference between PropertyMetadata and FrameworkPropertyMetadata is that the latter allows to specify a set of FrameworkPropertyMetadataOptions.

For example, specifying FrameworkPropertyMetadataOptions.AffectsRender cares for initiating a re-rendering of a UIElement on which the property has changed. Without this flag you would have to do that manually in a PropertyChangedCallback.

like image 5
Clemens Avatar answered Nov 08 '22 14:11

Clemens