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自訂中繼資料屬性的設定作業之前進行檢查。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.

適用於

另請參閱