DependencyPropertyKey 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供對只讀相依性屬性的有限寫入存取的相依性屬性標識碼。
public ref class DependencyPropertyKey sealed
public sealed class DependencyPropertyKey
type DependencyPropertyKey = class
Public NotInheritable Class DependencyPropertyKey
- 繼承
-
DependencyPropertyKey
下列範例會註冊只讀相依性屬性,並針對其他類別成員的兩個用途使用索引鍵:實作 get “wrapper”,以及做為受保護判斷作業的標識符,該作業會根據其他屬性值的計算來設定值。
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 實例是使用 方法 RegisterReadOnly 或 RegisterAttachedReadOnly取得相依性屬性註冊呼叫的傳回值。
註冊相依性屬性的類型可以使用呼叫中的 DependencyPropertyKey,以 SetValue 和 ClearValue,將屬性的值調整為類別邏輯的一部分。 如果金鑰的存取層級允許,相關類別也可以使用金鑰和相依性屬性。 例如,您可以將索引鍵宣告為內部,而相同元件內的其他類型也可以設定該相依性屬性。
只讀相依性屬性註冊所傳回的 DependencyPropertyKey 不應公開,因為公開索引鍵會使屬性設定為可設定,因而使將它註冊為唯讀相依性屬性的點失敗。 此外,公開索引鍵會導致可用的相依性屬性行為與其 Common Language Runtime (CLR) 屬性包裝函式實作不符,這是錯誤的類別設計。
您應該改為將 DependencyPropertyKey 的 DependencyProperty 值公開為類別上的 public static readonly
DependencyProperty,而不是公開索引鍵本身。 這可讓 屬性傳回特定屬性系統作業的有效相依性屬性標識碼,例如列舉本機設定值。 不過,因此取得的標識碼對於許多屬性系統作業而言,DependencyProperty 沒有完整的功能。
Dependency |
取得與此特製化只讀相依性屬性標識符相關聯的相依性屬性標識符。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設哈希函式。 (繼承來源 Object) |
Get |
取得目前實例的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object的淺層複本。 (繼承來源 Object) |
Override |
覆寫這個相依性屬性標識碼所表示之只讀相依性屬性的元數據。 |
To |
傳回表示目前 物件的字串。 (繼承來源 Object) |
產品 | 版本 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |