Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PropertyMetadata.IsSealed Property

 

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.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

protected bool IsSealed { get; }

Property Value

Type: System.Boolean

true if the metadata instance is immutable; otherwise, false.

Various properties of PropertyMetadata, such as DefaultValue, are defined in the object model as read-write. This is so those properties can be adjusted after initialization of the PropertyMetadata object itself. 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. At the time of one of these calls, OnApply is called, and the value of this property is set to true.

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;
        }
    }
}

.NET Framework
Available since 3.0
Return to top
Show:
© 2017 Microsoft