Thursday, 20 August 2015

Dependency Properties And Attached Properties

How different is WPF property System?

CLF Properties:CLR property is just a wrapper around private variables.  It uses get or set methods to retrieve the stored value of a variable.  And this property is associated with the Class that encloses it or its extended object hierarchy.

Dependency Properties:On the other hand, the purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs. These other inputs might include external properties such as user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements in the object tree. In addition, a dependency property can be implemented to provide callbacks that can propagate changes to other properties. 

Attached Properties:Attached properties are a special form of dependency property.  They exist so that a child element can store a value associated with a property defined on an ancestor element.  This is commonly used in the interaction between elements and the WPF layout infrastructure.

Difference between Dependency and Attached Properties:1/ Dependency properties are wrapped in CLR property where as Attached properties are not.
2/ Attached properties and normal dependency properties include the methods used to register them with the property system. For attached properties
DependencyProperty.RegisterAttached, .RegisterAttachedReadOnly & for dependency properties .Register and .RegisterReadOnly.
3/ On the basis of Where the property is stored, Attached properties are stored on elements which consume the property and not by the element which exposes the attached property.
4/ Attached properties allows container to create a property which can be used by any child UI elements.  Where as dependency property is associated with that particular elements and can help in notification of changes and reacting to that changes

No comments:

Post a Comment