代码改变世界

What makes data binding work?

2011-12-25 23:34  一一九九  阅读(188)  评论(0编辑  收藏  举报

The Wpf property system allows properties to paritcipate in data binding, styling, animation, and server other exciting features. A property that is registerd with the wpf property system is called a dependency property.

A property must be a dependency property to be the target of a data binding.

Dependency properties include metadata about the property, such as the default value for the property, the default binding mode, and other miscellaneous items. dependency properties alse provide automatic change notification.

dependency properties are the foundation for much of wpf. you can get a lot out of wpf without becoming an expert in them. however, if you want to take full advantage of the api, then you will want to dig deeper.  There are many good resources on the web. Be sure to search for both “dependencyObject” as well as “DependencyProperty” when doing your research.

unli ke the target of a data binding, data sources are not required to be dependency properties. However, if you want to use a binding mode other than oneway, your properties need to implement some mechanism for change notification. wpf uses two methods for monitoring change notifications. the first is to raise an event in your property setter that is name after property plus “changed” . the second method is to implement INotifyPropertychanged on the class that owns the property.

From <Sams.Teach.Yourself.WPF.in.24.Hours.Jun.2008>