Export (0) Print
Expand All

PropertyMap Class

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

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

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.

  NameDescription
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.
Top

  NameDescription
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.
Top

  NameDescription
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.)
Top

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

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()
{
    elemHost.PropertyMap.Add(
        "Margin",
        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()
{
    wfHost.PropertyMap.Remove("FlowDirection");

    wfHost.PropertyMap.Add(
        "FlowDirection",
        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 : 
            System.Windows.FlowDirection.LeftToRight;
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft