PropertyMap Classe

Definição

Fornece uma forma de traduzir valores de propriedades entre controlos do Windows Forms e elementos do 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
Herança
PropertyMap
Atributos

Exemplos

O exemplo de código seguinte mostra como adicionar um mapeamento para a Margin propriedade a um ElementHost controlo.

// 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

O seguinte exemplo de código mostra como substituir o mapeamento padrão da FlowDirection propriedade num WindowsFormsHost controlo.

// 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

Observações

Use a classe PropertyMap para definir translações entre propriedades Windows Forms e propriedades Windows Presentation Foundation (WPF) numa aplicação híbrida. As ElementHost.PropertyMap propriedades e WindowsFormsHost.PropertyMap nas ElementHost classes e WindowsFormsHost definem mapeamentos de uma tecnologia para outra.

Para mais informações, consulte Walkthrough: Mapear Propriedades Usando o Controlo ElementHost e Walkthrough: Mapear Propriedades Usando o Elemento WindowsFormsHost.

Construtores

Name Description
PropertyMap()

Inicializa uma nova instância da PropertyMap classe.

PropertyMap(Object)

Inicializa uma nova instância da PropertyMap classe com o objeto fonte dado.

Propriedades

Name Description
DefaultTranslators

Obtém uma coleção de mapeamentos de propriedades que são definidos por defeito.

Item[String]

Recebe ou define o PropertyTranslator delegado para a propriedade dada.

Keys

Obtém um ICollection objeto contendo os nomes das propriedades na PropertyMap coleção.

SourceObject

Obtém o objeto que tem as propriedades a ser traduzido.

Values

Obtém um ICollection contendo os tradutores de propriedades na PropertyMap coleção.

Métodos

Name Description
Add(String, PropertyTranslator)

Adiciona um PropertyTranslator delegado para a propriedade dada à PropertyMap.

Apply(String)

Executa o tradutor de propriedades para a propriedade dada, com base no valor atual da propriedade do objeto de origem.

ApplyAll()

Executa o tradutor de propriedades para cada propriedade mapeada, com base nos valores atuais das propriedades do objeto de origem.

Clear()

Remove todos os mapeamentos de propriedades.

Contains(String)

Recebe um valor que indica se a propriedade dada está mapeada.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
Remove(String)

Elimina a propriedade dada do mapeamento.

Reset(String)

Restaura o mapeamento de propriedades padrão para a propriedade dada.

ResetAll()

Restaura os mapeamentos de propriedades padrão.

ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

evento

Name Description
PropertyMappingError

Ocorre quando uma exceção é criada por um tradutor de propriedades.

Aplica-se a

Ver também