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 識別碼對於許多屬性系統作業沒有 的完整功能。
屬性
DependencyProperty |
取得與這個特定的相依性屬性識別項關聯的相依性屬性識別項。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
OverrideMetadata(Type, PropertyMetadata) |
覆寫由相依性屬性識別項表示之唯讀相依性屬性的中繼資料。 |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |