Export (0) Print
Expand All

PropertyMetadata.Merge Method

Merges this metadata with the base metadata.

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

'Declaration
Protected Overridable Sub Merge ( _
	baseMetadata As PropertyMetadata, _
	dp As DependencyProperty _
)

Parameters

baseMetadata
Type: System.Windows.PropertyMetadata

The base metadata to merge with this instance's values.

dp
Type: System.Windows.DependencyProperty

The dependency property to which this metadata is being applied.

This method is used internally when metadata is being overridden (OverrideMetadata method).

Notes to Inheritors

Class implementations that derive from PropertyMetadata should override this method to account for any metadata properties they have added in their implementations. For instance, your implementation might have added a new flagwise enumeration value, and the Merge implementation should then be able to combine those flags correctly.

Always call the base implementation prior to your implementation code, because the base implementation takes care of merging all the properties already defined on the PropertyMetadata type.

The exact behavior of the merge is up to you. You could choose to have values combined, revert to base value if the derived metadata were left at the default, or many other behaviors based on the types of properties you have added to your particular metadata class, and their meanings.

The following example implements a merge for a custom metadata type that adds an additional property to the property metadata.

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

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft