DependencyProperty 类

定义

警告

此 API 现已过时。

一种特殊类型的属性,可以定义为或附加到 DependencyObjectA special kind of property that can be defined or attached to a DependencyObject. 有三种类型的依赖属性:实例属性、元属性和附加属性。There are three kinds of dependency properties: instance properties, meta properties, and attached properties. 此类不能被继承。This class cannot be inherited.

public ref class DependencyProperty sealed : System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class DependencyProperty : System.Runtime.Serialization.ISerializable
[System.Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
[System.Serializable]
public sealed class DependencyProperty : System.Runtime.Serialization.ISerializable
type DependencyProperty = class
    interface ISerializable
Public NotInheritable Class DependencyProperty
Implements ISerializable
继承
DependencyProperty
属性
实现

示例

下面的示例演示如何注册 DependencyProperty,以供 DependencyObject 使用。The following example shows how to register a DependencyProperty for use by a DependencyObject. 此代码示例是发送电子邮件 SDK 示例的一部分,来自 SendMailActivity.cs 文件。This code example is part of the Send Email SDK sample and is from the SendMailActivity.cs file. 有关详细信息,请参阅发送邮件活动For more information, see Send Mail Activity.

// Define the DependencyProperty objects for all of the Properties
// ...and Events exposed by this activity
public static DependencyProperty FromProperty = DependencyProperty.Register("From", typeof(string), typeof(SendEmailActivity), new PropertyMetadata("someone@example.com"));
public static DependencyProperty ToProperty = DependencyProperty.Register("To", typeof(string), typeof(SendEmailActivity), new PropertyMetadata("someone@example.com"));
' Define the DependencyProperty objects for all of the Properties 
' ...and Events exposed by me activity
Public Shared FromEmailProperty As DependencyProperty = DependencyProperty.Register("From", GetType(String), GetType(SendEmailActivity), New PropertyMetadata("someone@example.com"))
Public Shared ToProperty As DependencyProperty = DependencyProperty.Register("To", GetType(String), GetType(SendEmailActivity), New PropertyMetadata("someone@example.com"))

注解

备注

本材料讨论的类型和命名空间已废弃不用。This material discusses types and namespaces that are obsolete. 有关详细信息,请参阅 Windows Workflow Foundation 4.5 中弃用的类型For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

依赖属性支持三种用例。Dependency properties support three use cases. 第一种,如果活动的实例属性通过使用依赖属性来实现,则可以为该属性分配 ActivityBind 而不是实际值。First, if an instance property of an activity is implemented by using a dependency property, that property can be assigned an ActivityBind instead of an actual value. 第二种,作为元数据的活动属性(即,不能在运行时更改该值)应通过使用依赖属性并指定 Metadata 选项来实现。Second, activity properties that are metadata (that is, the value cannot change at run time) should be implemented by using dependency properties, specifying the Metadata option. 第三种,依赖属性支持附加属性。附加属性是动态应用到依赖对象的属性。Third, dependency properties support attached properties, which are properties that are applied to dependency objects dynamically.

属性

DefaultMetadata

获取 PropertyMetadata,它表示此 DependencyProperty 的用户定义的数据。Gets the PropertyMetadata that represents user-defined data for this DependencyProperty.

IsAttached

获取一个属性,该属性指示此 DependencyProperty 是否通过注册与 DependencyObject 关联。Gets the property that indicates whether this DependencyProperty is associated to a DependencyObject by registration.

IsEvent

获取一个属性,该属性指示 DependencyProperty 是否是事件 DelegateGets the property that indicates whether the DependencyProperty is an event Delegate.

Name

获取 NameDependencyPropertyGets the Name of the DependencyProperty.

OwnerType

获取 TypeDependencyPropertyGets the Type of the DependencyProperty.

PropertyType

获取 Type 中存储的值的 DependencyPropertyGets the Type of the value stored in the DependencyProperty.

ValidatorType

获取实现特定于 Type 的验证逻辑的 DependencyPropertyGets the Type implementing validation logic specific to the DependencyProperty.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FromName(String, Type)

获取基于 DependencyPropertyName 的已注册 OwnerTypeGets the registered DependencyProperty based on the Name and OwnerType.

FromType(Type)

创建属于特定 IListDependencyProperty 类型的 TypeCreates an IList of type DependencyProperty that belong to a specific Type.

GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Register(String, Type, Type)

初始化 DependencyProperty 类的新实例,它根据输入参数将属性参数化。Initializes a new instance of the DependencyProperty class that has the properties parameterized according to the input parameters.

Register(String, Type, Type, PropertyMetadata)

初始化 DependencyProperty 类的新实例,它根据输入参数将属性参数化。Initializes a new instance of the DependencyProperty class that has the properties parameterized according to the input parameters.

RegisterAttached(String, Type, Type)

初始化 DependencyProperty 类的新实例,它根据输入参数将属性参数化。Initializes a new instance of the DependencyProperty class that has the properties parameterized according to the input parameters. 此实例旨在声明在对象上使用的属性而不是所属类型的对象。This instance is intended to declare properties that are used on objects other than the objects of owning type.

RegisterAttached(String, Type, Type, PropertyMetadata)

初始化 DependencyProperty 类的新实例,它根据输入参数将属性参数化。Initializes a new instance of the DependencyProperty class that has the properties parameterized according to the input parameters.

RegisterAttached(String, Type, Type, PropertyMetadata, Type)

初始化 DependencyProperty 类的新实例,它根据输入参数将属性参数化。Initializes a new instance of the DependencyProperty class that has the properties parameterized according to the input parameters.

ToString()

重写 Object 方法,从而返回 Name 属性值。Overrides the Object method to return the Name property value.

显式接口实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用序列化目标对象时所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data required to serialize the target object.

适用于