This documentation is archived and is not being maintained.

PropertyMap Class

Provides a way to translate property values between Windows Forms controls and Windows Presentation Foundation (WPF) elements.


Namespace:  System.Windows.Forms.Integration
Assembly:  WindowsFormsIntegration (in WindowsFormsIntegration.dll)

[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public class PropertyMap
<PropertyMap .../>

The PropertyMap type exposes the following members.

Public methodPropertyMap()Initializes a new instance of the PropertyMap class.
Public methodPropertyMap(Object)Initializes a new instance of the PropertyMap class with the given source object.

Protected propertyDefaultTranslatorsGets a collection of property mappings which are defined by default.
Public propertyItemGets or sets the PropertyTranslator delegate for the given property.
Public propertyKeysGets an ICollection object containing the property names in the PropertyMap collection.
Protected propertySourceObjectGets the object which has the properties to be translated.
Public propertyValuesGets an ICollection containing the property translators in the PropertyMap collection.

Public methodAddAdds a PropertyTranslator delegate for the given property to the PropertyMap.
Public methodApplyRuns the property translator for the given property, based on the source object's current property value.
Public methodApplyAllRuns the property translator for each mapped property, based on the source object's current property values.
Public methodClearRemoves all property mappings.
Public methodContainsGets a value indicating whether the given property is mapped.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveDeletes the given property from the mapping.
Public methodResetRestores the default property mapping for the given property.
Public methodResetAllRestores the default property mappings.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public eventPropertyMappingErrorOccurs when an exception is raised by a property translator.

Use the PropertyMap class to define translations between Windows Forms properties and Windows Presentation Foundation (WPF) properties in a hybrid application. The ElementHost.PropertyMap and WindowsFormsHost.PropertyMap properties on the ElementHost and WindowsFormsHost classes define mappings from one technology to the other.

For more information, see Walkthrough: Mapping Properties Using the ElementHost Control and Walkthrough: Mapping Properties Using the WindowsFormsHost Element.

The following code example shows how to add a mapping for the Margin property to an ElementHost control.

// The AddMarginMapping method adds a new property mapping
// for the Margin property.
private void AddMarginMapping()
        new PropertyTranslator(OnMarginChange));

// The OnMarginChange method implements the mapping 
// from the Windows Forms Margin property to the
// Windows Presentation Foundation Margin property.
// The provided Padding value is used to construct 
// a Thickness value for the hosted element's Margin
// property.
private void OnMarginChange(object h, String propertyName, object value)
    ElementHost host = h as ElementHost;
    Padding p = (Padding)value;
    System.Windows.Controls.Button wpfButton = 
        host.Child as System.Windows.Controls.Button;

    Thickness t = new Thickness(p.Left, p.Top, p.Right, p.Bottom );

    wpfButton.Margin = t;

The following code example shows how to replace the default mapping for the FlowDirection property on a WindowsFormsHost control.

// The ReplaceFlowDirectionMapping method replaces the  
// default mapping for the FlowDirection property.
private void ReplaceFlowDirectionMapping()

        new PropertyTranslator(OnFlowDirectionChange));

// The OnFlowDirectionChange method translates a 
// Windows Presentation Foundation FlowDirection value 
// to a Windows Forms RightToLeft value and assigns
// the result to the hosted control's RightToLeft property.
private void OnFlowDirectionChange(object h, String propertyName, object value)
    WindowsFormsHost host = h as WindowsFormsHost;
    System.Windows.FlowDirection fd = (System.Windows.FlowDirection)value;
    System.Windows.Forms.CheckBox cb = host.Child as System.Windows.Forms.CheckBox;

    cb.RightToLeft = (fd == System.Windows.FlowDirection.RightToLeft ) ? 
        RightToLeft.Yes : RightToLeft.No;

// The cb_CheckedChanged method handles the hosted control's
// CheckedChanged event. If the Checked property is true,
// the flow direction is set to RightToLeft, otherwise it is
// set to LeftToRight.
private void cb_CheckedChanged(object sender, EventArgs e)
    System.Windows.Forms.CheckBox cb = sender as System.Windows.Forms.CheckBox;

    wfHost.FlowDirection = ( cb.CheckState == CheckState.Checked ) ? 
            System.Windows.FlowDirection.RightToLeft : 

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • SecurityAction.LinkDemand 

    for full trust for the immediate caller. This member cannot be used by partially trusted code.

  • SecurityAction.InheritanceDemand 

    for full trust for inheritors. This member cannot be inherited by partially trusted code.

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.