• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

icehyp

icehyp
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

Dependency Properties Overview

Dependency Properties and CLR Properties

Windows Presentation Foundation properties are generally exposed as common language runtime (CLR) properties. An application developer could interact with Windows Presentation Foundation properties directly and does not need to worry about what goes on "behind the scenes." However, Windows Presentation Foundation application developers should become familiar with some of the features of the property system, so that they can take advantage of these features.

The function of the overall Windows Presentation Foundation property system, and of the dependency property concept in particular, is to provide facilities to compute a given property's value based on other properties. These other properties might include system properties such as themes and user preference, just-in-time property determination mechanisms such as databinding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements. In addition, a dependency property can be implemented to provide self-contained validation, default values, callbacks that monitor changes to other properties, and a system that can coerce property values based on potentially runtime information. Subclasses can also change property specifics by overriding a property's metadata, rather than having to completely re-implement the property.


Not All Windows Presentation Foundation Properties Are Dependency Properties

Note that there are a number of properties defined on Windows Presentation Foundation elements that are not dependency properties. By and large, properties were implemented as dependency properties only when there were needs to support at least one of the scenarios enabled by the property system: databinding, styling, animation, default value support, inheritance, attached properties, or invalidation. There are also a few cases of properties that are settable in XAML that are not necessarily backed by dependency properties. The API reference pages for the property in question will note whether or not any given property is a dependency property, and will also report some specifics of that particular dependency property's characteristics.

In general, properties that are read/write and that are implemented on UIElement or ContentElement or any class that inherits from these are implemented as dependency properties. But there are exceptions, including a few cases of read-only dependency properties, and some read-write properties with no dependency property backing.

Dependency Property Value Determination

When you get the value of a dependency property, you are potentially obtaining a value that was set on that property through any one of the other property-based inputs that participate in the Windows Presentation Foundation property system. These are applied in a particular order. See also Dependency Property Value Precedence topic (there are some slight variations in precedence involving style trigger precedence that are discussed there).

  1. Running animations. Once started, and regardless of whether they were declared directly, in templates, or in styles, animations are promoted over even locally set values. For details on the purpose and use of animations and storyboards, see Animation Overview.

  2. Locally set values, such as XAML attributes or direct sets of the property on an instance. Data binding or resource references are considered equivalent to locally set values in terms of precedence.

  3. Applied templates (templates are a specialized element construction technique used in styles).

  4. Implicit by-Type styles in page or application.

  5. Explicit keyed styles in page or application.

  6. Theme styles. These are typically applied to common controls, such as Button.

  7. Property value inheritance - see Property Value Inheritance for details.

  8. Dependency property default value; this is established when registering the dependency property with the property system, and can also be overridden along with other dependency property metadata by any subclass that either adds itself as owner or chooses to otherwise override the base implementation's metadata.

posted on 2006-08-15 10:47  icehyp  阅读(242)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3