PropertyMap Clase

Definición

Proporciona un medio para traducir valores de propiedad entre controles de Windows Forms y elementos de Windows Presentation Foundation (WPF).

public ref class PropertyMap
public class PropertyMap
[System.Security.SecurityCritical]
public class PropertyMap
type PropertyMap = class
[<System.Security.SecurityCritical>]
type PropertyMap = class
Public Class PropertyMap
Herencia
PropertyMap
Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo agregar una asignación para la Margin propiedad a un 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 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

En el ejemplo de código siguiente se muestra cómo reemplazar la asignación predeterminada de la FlowDirection propiedad en un 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;
}
' 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

Comentarios

Use la PropertyMap clase para definir traducciones entre propiedades de Windows Forms y propiedades de Windows Presentation Foundation (WPF) en una aplicación híbrida. Las ElementHost.PropertyMap propiedades y de las ElementHost clases y WindowsFormsHost.PropertyMap WindowsFormsHost definen asignaciones de una tecnología a la otra.

Para obtener más información, vea Walkthrough: Mapping Properties Using the ElementHost Control and Walkthrough: Mapping Properties Using the WindowsFormsHost Element.

Constructores

PropertyMap()

Inicializa una nueva instancia de la clase PropertyMap.

PropertyMap(Object)

Inicializa una nueva instancia de la clase PropertyMap con el objeto de origen proporcionado.

Propiedades

DefaultTranslators

Obtiene una colección de asignaciones de propiedad que se definen de forma predeterminada.

Item[String]

Obtiene o establece el delegado del PropertyTranslator para la propiedad especificada.

Keys

Obtiene un objeto ICollection que contiene los nombres de propiedad de la colección PropertyMap.

SourceObject

Obtiene el objeto que tiene las propiedades que se deben traducir.

Values

Obtiene un ICollection que contiene los traductores de propiedades de la colección PropertyMap.

Métodos

Add(String, PropertyTranslator)

Agrega un delegado del PropertyTranslator para la propiedad especificada al PropertyMap.

Apply(String)

Ejecuta el traductor de propiedades para la propiedad proporcionada, según el valor de propiedad actuales del objeto de origen.

ApplyAll()

Ejecuta el traductor de propiedades para cada propiedad asignada, según los valores de propiedad actuales del objeto de origen.

Clear()

Quita todas las asignaciones de propiedad.

Contains(String)

Obtiene un valor que indica si la propiedad determinada se asigna.

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
Remove(String)

Elimina la propiedad especificada de la asignación.

Reset(String)

Restaura la asignación de propiedad predeterminada para la propiedad determinada.

ResetAll()

Restaura las asignaciones de propiedad predeterminadas.

ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Eventos

PropertyMappingError

Se produce cuando un traductor de propiedad genera una excepción.

Se aplica a

Consulte también