PropertyMetadata.CoerceValueCallback 属性

定义

获取或设置对此元数据中所指定 CoerceValueCallback 实现的引用。Gets or sets a reference to a CoerceValueCallback implementation specified in this metadata.

public:
 property System::Windows::CoerceValueCallback ^ CoerceValueCallback { System::Windows::CoerceValueCallback ^ get(); void set(System::Windows::CoerceValueCallback ^ value); };
public System.Windows.CoerceValueCallback CoerceValueCallback { get; set; }
member this.CoerceValueCallback : System.Windows.CoerceValueCallback with get, set
Public Property CoerceValueCallback As CoerceValueCallback

属性值

一个 CoerceValueCallback 实现引用。A CoerceValueCallback implementation reference.

异常

将元数据属性应用于依赖属性操作后,无法设置该属性。Cannot set a metadata property once it is applied to a dependency property operation.

注解

属性元数据中的回调通常不是包含类型上的公共成员, 因此, 此属性的值对于只使用现有依赖属性的元数据的大多数方案而言并不重要。The callbacks in property metadata are not typically public members on the containing type, so the value of this property is not important for most scenarios that just consume an existing dependency property's metadata. 此属性被公开的一个原因是, 如果基本元数据和重写/添加元数据都指定CoerceValueCallback, 则元数据子类可以执行其所需的合并逻辑。One reason this property is exposed is so that metadata subclasses can perform their desired merge logic if both base metadata and overriding/adding metadata specify a CoerceValueCallback. 但是, 的默认合并逻辑CoerceValueCallback是替换前一个逻辑。However, the default merge logic for a CoerceValueCallback is to replace the previous one.

CoerceValueCallback在对象模型中定义为读写。CoerceValueCallback is defined in the object model as read-write. 这样CoerceValueCallback就可以在PropertyMetadata对象本身初始化后进行调整。This is so CoerceValueCallback can be adjusted after initialization of the PropertyMetadata object itself. 但是, 在调用RegisterAddOwnerOverrideMetadata的过程中使用元数据后, 属性系统将密封该元数据实例, 并且属性现在被视为不可变。However, once the metadata is consumed as part of a call to Register, AddOwner, or OverrideMetadata, the property system will seal that metadata instance and the properties are now considered immutable. 如果尝试设置CoerceValueCallbackIsSealedtrue , 此元数据实例将引发异常。Attempting to set CoerceValueCallback once IsSealed is true on this metadata instance will raise an exception.

适用于