What is a Dependency Property and when is it used? [duplicate]

旧时模样 提交于 2019-12-08 19:16:41

问题


Possible Duplicate:
What is a dependency property?

hi guys, I have been browsing through the net to find the definition of a dependency prop, but cannot find the simplest def for this.Can anyone help me with an example? Thanks


回答1:


There have already been a number of discussions here itself regarding this.Please go through some.

What is a dependency property?

What is the Dependency property in WPF

Dependency Property In WPF/SilverLight

How is dependency property implemented?

What is the difference between Property and Dependency Property

Dependency Property Uses in WPF

Also google and you can find some awesome articles.

http://joshsmithonwpf.wordpress.com/2007/06/22/overview-of-dependency-properties-in-wpf/

http://www.switchonthecode.com/tutorials/wpf-tutorial-introduction-to-dependency-properties

http://www.dotnetfunda.com/articles/article961-wpf-tutorial--dependency-property-.aspx




回答2:


Here is a quote from the WPF 4 Unleashed book:

WPF introduces a new type of property called a dependency property that is used throughout the platform to enable styling, automatic data binding, animation, and more. You might first meet this concept with skepticism, as it complicates the picture of .NET types having simple fields, properties, methods, and events. But when you understand the problems that dependency properties solve, you will likely accept them as a welcome addition.

A dependency property depends on multiple providers for determining its value at any point in time. These providers could be an animation continuously changing its value, a parent element whose property value propagates down to its children, and so on. Arguably the biggest feature of a dependency property is its built-in ability to provide change notification.

The motivation for adding such intelligence to properties is to enable rich functionality directly from declarative markup. The key to WPF’s declarative-friendly design is its heavy use of properties. Button, for example, has 111 public properties (98 of which are inherited from Control and its base classes)! Properties can be easily set in XAML (directly or by using a design tool) without any procedural code. But without the extra plumbing in dependency properties, it would be hard for the simple action of setting properties to get the desired results without the need to write additional code.



来源:https://stackoverflow.com/questions/5193144/what-is-a-dependency-property-and-when-is-it-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!