Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
CLR property is just a wrapper around private variables. It uses Get / Set methods to retrieve and store value of a variable into it. A CLR property gives you only one block in which you can write code to invoke whenever a property is get or set.
Dependency Property it is not stored in a field of your object, but in a dictionary of keys and values provided by the base class Dependency Object. The key of an entry is the name of the property and the value is the value you want to set.
WPF has provided some extended services to the CLR property that we can collectively call Dependency Properties. A Dependency Property is a property whose value depends on the external sources, such as animation, data binding, styles, or visual tree inheritance. Not only this, but a Dependency Property also has the built-in feature of providing notification when the property has changed, data binding and styling.
To work with dependency property, you must derive your class from Dependency Object as the whole observer which holds the new Property System is defined within the Dependency Object.
E.g.
public static readonly DependencyProperty TestProperty =
DependencyProperty.Register("Test", typeof(string), typeof(Window1));
public string Test
{
get
{
return this.GetValue(TestProperty) as string;
}
set
{
this.SetValue(MyCustomProperty, value);
}
}
Whereas when you set a value of a Dependency Property it is not stored in a field of your object, but in a dictionary of keys and values provided by the base class DependencyObject. The key of an entry is the name of the property and the value is the value you want to set