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

'Declaration
<PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")> _
<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
Public Class PropertyMap
'Usage
Dim instance As PropertyMap
<PropertyMap .../>

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.Remove("FlowDirection")

    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, _
        RightToLeft.No)

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, _
    System.Windows.FlowDirection.LeftToRight)

End Sub

System.Object
  System.Windows.Forms.Integration.PropertyMap

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0
Show: