Partager via


PropertyMap Classe

Définition

Fournit un moyen de traduire des valeurs de propriété entre les contrôles Windows Forms et les éléments WPF (Windows Presentation Foundation).

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
Héritage
PropertyMap
Attributs

Exemples

L’exemple de code suivant montre comment ajouter un mappage pour la Margin propriété à un ElementHost contrôle.

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

L’exemple de code suivant montre comment remplacer le mappage par défaut pour la FlowDirection propriété sur un WindowsFormsHost contrôle.

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

Remarques

Utilisez la PropertyMap classe pour définir des traductions entre les propriétés Windows Forms et les propriétés WPF (Windows Presentation Foundation) dans une application hybride. Les ElementHost.PropertyMap propriétés et WindowsFormsHost.PropertyMap les propriétés des classes et WindowsFormsHost des ElementHost classes définissent des mappages d’une technologie à l’autre.

Pour plus d’informations, consultez Procédure pas à pas : Propriétés de mappage à l’aide du contrôle ElementHost et procédure pas à pas : propriétés de mappage à l’aide de l’élément WindowsFormsHost.

Constructeurs

Nom Description
PropertyMap()

Initialise une nouvelle instance de la classe PropertyMap.

PropertyMap(Object)

Initialise une nouvelle instance de la PropertyMap classe avec l’objet source donné.

Propriétés

Nom Description
DefaultTranslators

Obtient une collection de mappages de propriétés qui sont définis par défaut.

Item[String]

Obtient ou définit le PropertyTranslator délégué pour la propriété donnée.

Keys

Obtient un ICollection objet contenant les noms de propriétés dans la PropertyMap collection.

SourceObject

Obtient l’objet qui a les propriétés à traduire.

Values

Obtient un ICollection conteneur des traducteurs de propriétés dans la PropertyMap collection.

Méthodes

Nom Description
Add(String, PropertyTranslator)

Ajoute un PropertyTranslator délégué pour la propriété donnée à la PropertyMappropriété .

Apply(String)

Exécute le traducteur de propriétés pour la propriété donnée, en fonction de la valeur de propriété actuelle de l’objet source.

ApplyAll()

Exécute le traducteur de propriétés pour chaque propriété mappée, en fonction des valeurs de propriété actuelles de l’objet source.

Clear()

Supprime tous les mappages de propriétés.

Contains(String)

Obtient une valeur indiquant si la propriété donnée est mappée.

Equals(Object)

Détermine si l’objet spécifié est égal à l’objet actuel.

(Hérité de Object)
GetHashCode()

Sert de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient la Type de l’instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Objectactuel.

(Hérité de Object)
Remove(String)

Supprime la propriété donnée du mappage.

Reset(String)

Restaure le mappage de propriétés par défaut pour la propriété donnée.

ResetAll()

Restaure les mappages de propriétés par défaut.

ToString()

Retourne une chaîne qui représente l’objet actuel.

(Hérité de Object)

Événements

Nom Description
PropertyMappingError

Se produit lorsqu’une exception est levée par un traducteur de propriétés.

S’applique à

Voir aussi