DependencyProperty DependencyProperty DependencyProperty DependencyProperty Class

定義

警告

此 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.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
繼承
DependencyPropertyDependencyPropertyDependencyPropertyDependencyProperty
屬性
實作

範例

下列範例將說明如何註冊 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 DefaultMetadata DefaultMetadata DefaultMetadata

取得 PropertyMetadata,它代表這個 DependencyProperty 的使用者定義資料。Gets the PropertyMetadata that represents user-defined data for this DependencyProperty.

IsAttached IsAttached IsAttached IsAttached

取得屬性,該屬性指出根據註冊,這個 DependencyProperty 是否與 DependencyObject 相關聯。Gets the property that indicates whether this DependencyProperty is associated to a DependencyObject by registration.

IsEvent IsEvent IsEvent IsEvent

取得屬性,這個屬性指出 DependencyProperty 是否是 Delegate 事件。Gets the property that indicates whether the DependencyProperty is an event Delegate.

Name Name Name Name

取得 NameDependencyPropertyGets the Name of the DependencyProperty.

OwnerType OwnerType OwnerType OwnerType

取得 TypeDependencyPropertyGets the Type of the DependencyProperty.

PropertyType PropertyType PropertyType PropertyType

取得儲存在 TypeDependencyProperty中值的 。Gets the Type of the value stored in the DependencyProperty.

ValidatorType ValidatorType ValidatorType ValidatorType

取得實作 Type 特定驗證邏輯的 DependencyPropertyGets the Type implementing validation logic specific to the DependencyProperty.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FromName(String, Type) FromName(String, Type) FromName(String, Type) FromName(String, Type)

取得根據 DependencyPropertyName 註冊的 OwnerTypeGets the registered DependencyProperty based on the Name and OwnerType.

FromType(Type) FromType(Type) FromType(Type) FromType(Type)

建立 IList 型別的 DependencyProperty,該型別屬性特定的 TypeCreates an IList of type DependencyProperty that belong to a specific Type.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Register(String, Type, Type) Register(String, Type, Type) Register(String, Type, Type) 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) Register(String, Type, Type, PropertyMetadata) Register(String, Type, Type, PropertyMetadata) 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) RegisterAttached(String, Type, Type) RegisterAttached(String, Type, Type) 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) RegisterAttached(String, Type, Type, PropertyMetadata) RegisterAttached(String, Type, Type, PropertyMetadata) 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) RegisterAttached(String, Type, Type, PropertyMetadata, Type) RegisterAttached(String, Type, Type, PropertyMetadata, Type) 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() ToString() ToString() ToString()

覆寫 Object 方法以傳回 Name 屬性值。Overrides the Object method to return the Name property value.

明確介面實作

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將序列化目標物件的所需資料填入 SerializationInfoPopulates a SerializationInfo with the data required to serialize the target object.

適用於