when to use Dependency Property in WP7 / Silverlight
What is the speciality of Dependency proper开发者_Go百科ty in Silverlight. I searched many sites but i won’t get a clear cut idea about this. Can any one let me know in what context this dependency property can be used in Silverlight.
Here is the simple rule of thumb. If you are creating a control (either a UserControl or a Custom templated control) add new properties using Dependency Properties. Otherwise its rare to create model or view model classes that derived from DependencyObject
you would just use standard properties perhaps with an implementation of INotifyPropertyChanged
.
Dependency properties are the basis for data binding. You can't use data binding on a property which isn't implemented as a DependencyProperty
. For similar reasons a property needs to be implemented as DependencyPropertry
if it is to be animated using Storyboard
animations.
When you create a UserControl. If your property is a normal public property like that :
public Double MyProperty
{
get;
set;
}
You won't be able to apply styling to the property.
You won't be able to apply an animation based on that property in Storyboards.
精彩评论