Need a short and clear definition for “Dependency Properties”

前端 未结 6 838
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 13:42

I\'m trying to figure out what exactly Dependency Properties are, but when I look anywhere for a definition, I only find \"how to use\" but not \"what it is\". Imagine you are

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 14:09

    A dependency property is a property that is backed by the WPF property system instead of by a field in the declaring class.

    The significance of this is that, because WPF owns the property, WPF can factor in various considerations when calculating the property value -- such as animations, styles and data bindings. Another consequence is that because properties are managed by WPF they don't have to be declared on the classes that conceptually have the state: hence, atttached properties, which allow e.g. a Grid to associate Grid-specific state with non-Grid objects.

    (By the way, I've mentioned WPF above because this is the main framework that uses DPs, but Windows Workflow Foundation also has the notion of dependency properties. So to be strictly correct a DP is a property that is backed by an external property system, specifically one which allows factors other than "the last set value" to come into play when getting the property value.)

提交回复
热议问题