什么是依赖属性?它的用途是什么? [英] What is a dependency property? What is its use?

查看:35
本文介绍了什么是依赖属性?它的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能性:
什么是依赖属性?

什么是依赖属性?它与普通财产有何不同?依赖属性的目的是什么?以及为什么使用它,何时使用?

What is a dependency property? How does it differ from a normal property? What is the purpose of dependency properties? And why it is used, when it is used?

推荐答案

依赖属性:由 DependencyProperty.

Dependency property: A property that is backed by a DependencyProperty.

依赖属性的目的是提供一种方法来基于其他输入的值来计算属性的值.

The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs.

这些其他输入可能包括系统属性(例如主题和用户偏好)、即时属性确定机制(例如数据绑定和动画/故事板)、多用途模板(例如资源和样式)或通过父级已知的值与元素树中其他元素的子关系.

These other inputs might include system properties such as themes and user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements in the element tree.

它具有以下功能:

  • 可以在样式中设置该属性.

  • The property can be set in a style.

属性可以通过数据绑定设置.

The property can be set through data binding.

可以使用动态资源引用来设置该属性.

The property can be set with a dynamic resource reference.

该属性可以自动从元素树中的父元素继承其值.

The property can inherit its value automatically from a parent element in the element tree.

该属性可以设置动画.

该属性可以在属性的先前值发生更改时报告,并且可以强制该属性值.

The property can report when the previous value of the property has been changed and the property value can be coerced.

属性向 WPF 报告信息,例如更改属性值是否应要求布局系统重新组合元素的视觉效果.

The property reports information to WPF, such as whether changing a property value should require the layout system to recompose the visuals for an element.

该属性在 Visual Studio 的 WPF 设计器中获得支持.例如,可以在属性"窗口中编辑该属性.

The property receives support in the WPF Designer for Visual Studio. For example, the property can be edited in the Properties window.

(内容取自 MSDN)

这篇关于什么是依赖属性?它的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆