PropertyMetadata.IsSealed 属性

定义

获取一个值,该值确定是否已通过某种方式将元数据应用于属性,从而导致该元数据实例变为不可变状态。Gets a value that determines whether the metadata has been applied to a property in some way, resulting in the immutable state of that metadata instance.

protected:
 property bool IsSealed { bool get(); };
protected bool IsSealed { get; }
member this.IsSealed : bool
Protected ReadOnly Property IsSealed As Boolean

属性值

如果元数据实例不可变,则为 true;否则为 falsetrue if the metadata instance is immutable; otherwise, false.

示例

下面的示例在IsSealed自定义元数据属性的 set 操作之前进行检查。The following example checks IsSealed prior to a set operation of a custom metadata property.

public Boolean SupportsMyFeature
{
    get { return _supportsMyFeature; }
    set { if (this.IsSealed != true) _supportsMyFeature = value; } //else may want to raise exception 
}
protected override void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
{
    base.Merge(baseMetadata, dp);
    MyCustomPropertyMetadata mcpm = baseMetadata as MyCustomPropertyMetadata;
    if (mcpm != null)
    {
        if (this.SupportsMyFeature == false)
        {//if not set, revert to base
            this.SupportsMyFeature = mcpm.SupportsMyFeature;
        }
    }
}

注解

的各种属性PropertyMetadata( DefaultValue例如) 在对象模型中定义为读写。Various properties of PropertyMetadata, such as DefaultValue, are defined in the object model as read-write. 这就是在初始化PropertyMetadata对象本身后可以调整这些属性。This is so those properties can be adjusted after initialization of the PropertyMetadata object itself. 但是, 在对RegisterAddOwnerOverrideMetadata的调用中, 将元数据应用于依赖属性后, 属性系统将密封该元数据实例, 并且属性现在被视为不可变。However, once the metadata is applied to a dependency property 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. 在其中一个调用时, OnApply将调用, 并将此属性的值设置为。 trueAt the time of one of these calls, OnApply is called, and the value of this property is set to true.

适用于

另请参阅