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返回的只读依赖属性注册不应成为公共的因为公开键便可以该属性可设置,从而与将作为只读依赖属性注册。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 的浅表副本。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)

适用于

另请参阅