Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
Public Class PropertyMap
<PropertyMap .../>

The PropertyMap type exposes the following members.

Public methodPropertyMapInitializes 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 the default hash function. (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 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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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