PropertyMap.Item Property (String)

 

Gets or sets the PropertyTranslator delegate for the given property.

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

public PropertyTranslator this[
	string propertyName
] { get; set; }

Parameters

propertyName
Type: System.String

The name of the property to map.

Property Value

Type: System.Windows.Forms.Integration.PropertyTranslator

The PropertyTranslator delegate corresponding to the property specified by propertyName.

Exception Condition
ArgumentNullException

propertyName is null or an empty string; the specified PropertyTranslator delegate is null.

ArgumentException

The property given by propertyName does not exist on SourceObject.

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

The following code example shows how to retrieve the PropertyTranslator delegate for the BackColor property of a ElementHost control.

// The ExtendBackColorMapping method adds a property
// translator if a mapping already exists.
private void ExtendBackColorMapping()
{
    if (elemHost.PropertyMap["BackColor"] != null)
    {
        elemHost.PropertyMap["BackColor"] += 
            new PropertyTranslator(OnBackColorChange);
    }
}

// The OnBackColorChange method assigns a specific image 
// to the hosted element's Background property.
private void OnBackColorChange(object h, String propertyName, object value)
{
    ElementHost host = h as ElementHost;
    System.Windows.Controls.Button wpfButton = 
        host.Child as System.Windows.Controls.Button;

    ImageBrush b = new ImageBrush(new BitmapImage(
        new Uri(@"file:///C:\WINDOWS\Santa Fe Stucco.bmp")));
    wpfButton.Background = b;
}

The following code example shows how to retrieve the PropertyTranslator delegate for the Background property of a WindowsFormsHost control.

// The ExtendBackgroundMapping method adds a property
// translator if a mapping already exists.
private void ExtendBackgroundMapping()
{
    if (wfHost.PropertyMap["Background"] != null)
    {
        wfHost.PropertyMap["Background"] += new PropertyTranslator(OnBackgroundChange);
    }
}

// The OnBackgroundChange method assigns a specific image 
// to the hosted control's BackgroundImage property.
private void OnBackgroundChange(object h, String propertyName, object value)
{
    WindowsFormsHost host = h as WindowsFormsHost;
    System.Windows.Forms.CheckBox cb = host.Child as System.Windows.Forms.CheckBox;
    ImageBrush b = value as ImageBrush;

    if (b != null)
    {
        cb.BackgroundImage = new System.Drawing.Bitmap(@"C:\WINDOWS\Santa Fe Stucco.bmp");
    }
}

.NET Framework
Available since 3.0
Return to top
Show: