DependencyPropertyKey DependencyPropertyKey DependencyPropertyKey DependencyPropertyKey Class

定義

為唯讀相依性屬性的有限寫入權限提供相依性屬性識別項。Provides a dependency property identifier for limited write access to a read-only dependency property.

public ref class DependencyPropertyKey sealed
public sealed class DependencyPropertyKey
type DependencyPropertyKey = class
Public NotInheritable Class DependencyPropertyKey
繼承
DependencyPropertyKeyDependencyPropertyKeyDependencyPropertyKeyDependencyPropertyKey

範例

下列範例會登錄唯讀相依性屬性,並也會使用金鑰,其他類別成員中的兩個目的: 實作 get 「 包裝函式 」,以及在計算根據設定的值判斷受保護的作業的識別碼其他屬性的值。The following example registers a read-only dependency property, and also uses the key for two purposes in other class members: implementing the get "wrapper", and as the identifier for a protected determination operation that sets the value based on calculations of other property values.

internal static readonly DependencyPropertyKey AquariumSizeKey = DependencyProperty.RegisterReadOnly(
  "AquariumSize",
  typeof(double),
  typeof(Aquarium),
  new PropertyMetadata(double.NaN)
);
public static readonly DependencyProperty AquariumSizeProperty =
  AquariumSizeKey.DependencyProperty;
public double AquariumSize
{
  get { return (double)GetValue(AquariumSizeProperty); }
}
Friend Shared ReadOnly AquariumSizeKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("AquariumSize", GetType(Double), GetType(Aquarium), New PropertyMetadata(Double.NaN))
Public Shared ReadOnly AquariumSizeProperty As DependencyProperty = AquariumSizeKey.DependencyProperty
Public ReadOnly Property AquariumSize() As Double
    Get
        Return CDbl(GetValue(AquariumSizeProperty))
    End Get
End Property

備註

DependencyPropertyKey 執行個體取得相依性屬性註冊呼叫使用方法的傳回值作為RegisterReadOnlyRegisterAttachedReadOnlyDependencyPropertyKey instances are obtained as the return value of a dependency property registration call using the methods RegisterReadOnly or RegisterAttachedReadOnly.

註冊相依性屬性的型別可以使用DependencyPropertyKey呼叫中SetValueClearValue,調整屬性的值做為類別邏輯的一部分。The types that register a dependency property can use the DependencyPropertyKey in calls to SetValue and ClearValue that adjust the property's value as part of class logic. 如果索引鍵的存取層級的允許,相關的類別也可以使用索引鍵和相依性屬性。If permitted by the access level of the key, related classes can use the key and the dependency property also. 比方說,您可以宣告為內部,索引鍵,和相同的組件內的其他類型也可以設定該相依性屬性。For instance, you can declare the key as internal, and other types within the same assembly can also set that dependency property.

DependencyPropertyKey傳回的唯讀相依性屬性註冊不能為 public,因為公開金鑰讓屬性成為可設定的失去了登錄唯讀相依性屬性的點。The DependencyPropertyKey returned by read-only dependency property registration should not be made public, because exposing the key makes the property settable, thus defeating the point of registering it as a read-only dependency property. 此外,公開索引鍵會讓不相符的可用的相依性屬性的行為及其通用語言執行平台 (CLR)common language runtime (CLR)屬性包裝函式實作,也就是不正確的類別設計。Also, exposing the key causes a mismatch between the available dependency property behaviors and its 通用語言執行平台 (CLR)common language runtime (CLR) property wrapper implementations, which is bad class design.

而不是公開本身的索引鍵,您應該改為公開DependencyProperty的值DependencyPropertyKey作為public static readonlyDependencyProperty類別上。Instead of exposing the key itself, you should instead expose the DependencyProperty value of the DependencyPropertyKey as a public static readonlyDependencyProperty on your class. 這可讓要傳回針對特定屬性系統作業,例如列舉本機設定值有效的相依性屬性識別項的屬性。This enables the property to return a valid dependency property identifier for certain property system operations such as enumerating locally set values. 不過,因此取得的識別碼沒有的完整功能DependencyProperty許多屬性系統作業。However, the identifier thus obtained does not have the full capabilities of a DependencyProperty for many property system operations.

屬性

DependencyProperty DependencyProperty DependencyProperty DependencyProperty

取得與這個特定的相依性屬性識別項關聯的相依性屬性識別項。Gets the dependency property identifier associated with this specialized read-only dependency property identifier.

方法

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

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
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)
OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata)

覆寫由相依性屬性識別項表示之唯讀相依性屬性的中繼資料。Overrides the metadata of a read-only dependency property that is represented by this dependency property identifier.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱