PropertyMap.Add Method (String, PropertyTranslator)


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

Namespace:   System.Windows.Forms.Integration
Assembly:  WindowsFormsIntegration (in WindowsFormsIntegration.dll)

public void Add(
	string propertyName,
	PropertyTranslator translator


Type: System.String

The name of the property to map.

Type: System.Windows.Forms.Integration.PropertyTranslator

The PropertyTranslator delegate which is called when propertyName changes.

Exception Condition

propertyName has an existing mapping.

When setting, if no PropertyTranslator exists for propertyName, the new delegate is added to the PropertyMap. If a PropertyTranslator already exists for propertyName, an InvalidOperationException is raised.

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()
        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 add a mapping for the Clip property to a WindowsFormsHost control.

// The AddClipMapping method adds a custom 
// mapping for the Clip property.
private void AddClipMapping()
        new PropertyTranslator(OnClipChange));

// The OnClipChange method assigns an elliptical clipping 
// region to the hosted control's Region property.
private void OnClipChange(object h, String propertyName, object value)
    WindowsFormsHost host = h as WindowsFormsHost;
    System.Windows.Forms.CheckBox cb = host.Child as System.Windows.Forms.CheckBox;

    if (cb != null)
        cb.Region = this.CreateClipRegion();

// The Window1_SizeChanged method handles the window's 
// SizeChanged event. It calls the OnClipChange method explicitly 
// to assign a new clipping region to the hosted control.
private void Window1_SizeChanged(object sender, SizeChangedEventArgs e)
    this.OnClipChange(wfHost, "Clip", null);

// The CreateClipRegion method creates a Region from an
// elliptical GraphicsPath.
private Region CreateClipRegion()
    GraphicsPath path = new GraphicsPath();


    path.AddEllipse(new System.Drawing.Rectangle( 
        (int)wfHost.ActualHeight ) );


    return( new Region(path) );

.NET Framework
Available since 3.0
Return to top