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.InheritanceDemand, Name := "FullTrust")>
Public Class PropertyMap


Initializes a new instance of the PropertyMap class.


Initializes a new instance of the PropertyMap class with the given source object.


Gets a collection of property mappings which are defined by default.


Gets or sets the PropertyTranslator delegate for the given property.


Gets an ICollection object containing the property names in the PropertyMap collection.


Gets the object which has the properties to be translated.


Gets an ICollection containing the property translators in the PropertyMap collection.

System_CAPS_pubmethodAdd(String, PropertyTranslator)

Adds a PropertyTranslator delegate for the given property to the PropertyMap.


Runs the property translator for the given property, based on the source object's current property value.


Runs the property translator for each mapped property, based on the source object's current property values.


Removes all property mappings.


Gets a value indicating whether the given property is mapped.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Deletes the given property from the mapping.


Restores the default property mapping for the given property.


Restores the default property mappings.


Returns a string that represents the current object.(Inherited from Object.)


Occurs 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 Sub AddMarginMapping()

    elemHost.PropertyMap.Add( _
        "Margin", _
        New PropertyTranslator(AddressOf OnMarginChange))

End Sub

' 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 Sub OnMarginChange( _
ByVal h As Object, _
ByVal propertyName As String, _
ByVal value As Object)

    Dim host As ElementHost = h
    Dim p As Padding = CType(value, Padding)
    Dim wpfButton As System.Windows.Controls.Button = host.Child

    Dim t As New Thickness(p.Left, p.Top, p.Right, p.Bottom)

    wpfButton.Margin = t

End Sub

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 Sub ReplaceFlowDirectionMapping()


    wfHost.PropertyMap.Add( _
        "FlowDirection", _
        New PropertyTranslator(AddressOf OnFlowDirectionChange))
End Sub

' 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 Sub OnFlowDirectionChange( _
ByVal h As Object, _
ByVal propertyName As String, _
ByVal value As Object)

    Dim host As WindowsFormsHost = h

    Dim fd As System.Windows.FlowDirection = _
        CType(value, System.Windows.FlowDirection)

    Dim cb As System.Windows.Forms.CheckBox = host.Child

    cb.RightToLeft = IIf(fd = System.Windows.FlowDirection.RightToLeft, _
        RightToLeft.Yes, _

End Sub

' 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 Sub cb_CheckedChanged( _
ByVal sender As Object, _
ByVal e As EventArgs)

    Dim cb As System.Windows.Forms.CheckBox = sender

    wfHost.FlowDirection = IIf(cb.CheckState = CheckState.Checked, _
    System.Windows.FlowDirection.RightToLeft, _

End Sub


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


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

.NET Framework
Available since 3.0

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

Return to top