--- title: "Windows Forms and WPF Property Mapping" titleSuffix: "" ms.date: "03/30/2017" helpviewer_keywords: - "property mapping [WPF interoperability]" - "Windows Forms [WPF], interoperability with" - "Windows Forms [WPF], WPF interoperation" - "interoperability [WPF], Windows Forms" - "WindowsFormsHost element property mapping [WPF]" ms.assetid: 999d8298-9c04-467d-a453-86e41002057d --- # Windows Forms and WPF Property Mapping The Windows Forms and [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] technologies have two similar but different property models. *Property mapping* supports interoperation between the two architectures and provides the following capabilities: - Makes it easy to map relevant property changes in the host environment to the hosted control or element. - Provides default handling for mapping the most commonly used properties. - Allows easy removal, overriding, or extending of default properties. - Ensures that property value changes on the host are automatically detected and translated to the hosted control or element. > [!NOTE] > Property-change events are not propagated up the hosting control or element hierarchy. Property translation is not performed if the local value of a property does not change because of direct setting, styles, inheritance, data binding, or other mechanisms that change the value of the property. Use the property on the element and the property on control to access property mapping. ## Property Mapping with the WindowsFormsHost Element The element translates default [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] properties to their Windows Forms equivalents using the following translation table. |Windows Presentation Foundation hosting|Windows Forms|Interoperation behavior| |---------------------------------------------|-------------------|-----------------------------| |

()|

()|The element sets the property of the hosted control and the property of the hosted control. Mapping is performed by using the following rules:

- If is a solid color, it is converted and used to set the property of the hosted control. The property is not set on the hosted control, because the hosted control can inherit the value of the property. **Note:** The hosted control does not support transparency. Any color assigned to must be fully opaque, with an alpha value of 0xFF.

- If is not a solid color, the control creates a bitmap from the property. The control assigns this bitmap to the property of the hosted control. This provides an effect which is similar to transparency. **Note:** You can override this behavior or you can remove the property mapping.| |||If the default mapping has not been reassigned, control traverses its ancestor hierarchy until it finds an ancestor with its property set. This value is translated to the closest corresponding Windows Forms cursor.

If the default mapping for the property has not been reassigned, the traversal stops on the first ancestor with set to `true`.| |

()|

()| maps to .

maps to .

is not mapped.

maps to .| || on the hosted control's |The set of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] properties is translated into a corresponding . When one of these properties changes, a new is created. For : is disabled. For or : is enabled.| || on the hosted control's |The set of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] properties is translated into a corresponding . When one of these properties changes, a new is created. For , , , , , , , or : is enabled. For , , , , , or : is disabled.| |







|

()|The set of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] properties is translated into a corresponding . When one of these properties changes, a new is created. The hosted Windows Forms control resizes based on the font size.

Font size in [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] is expressed as one ninety-sixth of an inch, and in Windows Forms as one seventy-second of an inch. The corresponding conversion is:

Windows Forms font size = [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] font size * 72.0 / 96.0.| |

()|

()|The property mapping is performed by using the following rules:

- If is a , use for .
- If is a , use the color of the with the lowest offset value for .
- For any other type, leave unchanged. This means the default is used.| |||When is set, element sets the property on the hosted control.| |||All four values of the property on the hosted Windows Forms control are set to the same value.

- Values greater than are set to .
- Values less than are set to .| |||- maps to = `true`. The hosted Windows Forms control is visible. Explicitly setting the property on the hosted control to `false` is not recommended.
- maps to = `true` or `false`. The hosted Windows Forms control is not drawn, and its area is collapsed.
- : The hosted Windows Forms control occupies space in the layout, but is not visible. In this case, the property is set to `true`. Explicitly setting the property on the hosted control to `false` is not recommended.| Attached properties on container elements are fully supported by the element. For more information, see [Walkthrough: Mapping Properties Using the WindowsFormsHost Element](walkthrough-mapping-properties-using-the-windowsformshost-element.md). ## Updates to Parent Properties Changes to most parent properties cause notifications to the hosted child control. The following list describes properties which do not cause notifications when their values change. - - - - For example, if you change the value of the property of the element, the property of the hosted control does not change. ## Property Mapping with the ElementHost Control The following properties provide built-in change notification. Do not call the method when you are mapping these properties: - AutoSize - BackColor - BackgroundImage - BackgroundImageLayout - BindingContext - CausesValidation - ContextMenu - ContextMenuStrip - Cursor - Dock - Enabled - Font - ForeColor - Location - Margin - Padding - Parent - Region - RightToLeft - Size - TabIndex - TabStop - Text - Visible The control translates default Windows Forms properties to their [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] equivalents by using the following translation table. For more information, see [Walkthrough: Mapping Properties Using the ElementHost Control](walkthrough-mapping-properties-using-the-elementhost-control.md). |Windows Forms hosting|Windows Presentation Foundation|Interoperation behavior| |---------------------------|-------------------------------------|-----------------------------| |

()|

() on the hosted element|Setting this property forces a repaint with an . If the property is set to `false` (the default value), this is based on the appearance of the control, including its , , properties, and any attached paint handlers.

If the property is set to `true`, the is based on the appearance of the control's parent, including the parent's , , properties, and any attached paint handlers.| |

()|

() on the hosted element|Setting this property causes the same behavior described for the mapping.| ||

() on the hosted element|Setting this property causes the same behavior described for the mapping.| |

()|

()|The Windows Forms standard cursor is translated to the corresponding [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] standard cursor. If the Windows Forms is not a standard cursor, the default is assigned.| |||When is set, the control sets the property on the hosted element.| |

()|







|The value is translated into a corresponding set of [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] font properties.| || on hosted element|If is `true`, is set to .

If is `false`, is set to .| || on hosted element|If is `true`, is set to .

If is `false`, is set to .| || on hosted element|Applies only when hosting a control.| || on hosted element|Applies only when hosting a control.| |

()|

()| maps to .

maps to .| |||The control sets the property on the hosted element by using the following rules:

- = `true` maps to .
- = `false` maps to .| ## See also - - - [WPF and Win32 Interoperation](wpf-and-win32-interoperation.md) - [WPF and Windows Forms Interoperation](wpf-and-windows-forms-interoperation.md) - [Walkthrough: Mapping Properties Using the WindowsFormsHost Element](walkthrough-mapping-properties-using-the-windowsformshost-element.md) - [Walkthrough: Mapping Properties Using the ElementHost Control](walkthrough-mapping-properties-using-the-elementhost-control.md)