开发者

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;
}
  1. You won't be able to apply styling to the property.

  2. You won't be able to apply an animation based on that property in Storyboards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜