Condividi tramite


PropertyMap Classe

Definizione

Fornisce un modo per convertire i valori delle proprietà tra i controlli Windows Form e gli elementi 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
Ereditarietà
PropertyMap
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come aggiungere un mapping per la Margin proprietà a un ElementHost controllo .

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

Nell'esempio di codice seguente viene illustrato come sostituire il mapping predefinito per la FlowDirection proprietà in un WindowsFormsHost controllo .

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

Commenti

Usare la PropertyMap classe per definire le traduzioni tra le proprietà di Windows Form e le proprietà wpf (Windows Presentation Foundation) in un'applicazione ibrida. Le ElementHost.PropertyMap proprietà e nelle ElementHost classi e WindowsFormsHost.PropertyMapWindowsFormsHost definiscono i mapping da una tecnologia all'altra.

Per altre informazioni, vedere Procedura dettagliata: Mapping delle proprietà tramite il controllo ElementHost e procedura dettagliata: Mapping delle proprietà tramite l'elemento WindowsFormsHost.

Costruttori

Nome Descrizione
PropertyMap()

Inizializza una nuova istanza della classe PropertyMap.

PropertyMap(Object)

Inizializza una nuova istanza della PropertyMap classe con l'oggetto di origine specificato.

Proprietà

Nome Descrizione
DefaultTranslators

Ottiene una raccolta di mapping delle proprietà definiti per impostazione predefinita.

Item[String]

Ottiene o imposta il PropertyTranslator delegato per la proprietà specificata.

Keys

Ottiene un ICollection oggetto contenente i nomi delle proprietà nell'insieme PropertyMap .

SourceObject

Ottiene l'oggetto con le proprietà da convertire.

Values

Ottiene un oggetto ICollection contenente i traduttori di proprietà nell'insieme PropertyMap .

Metodi

Nome Descrizione
Add(String, PropertyTranslator)

Aggiunge un PropertyTranslator delegato per la proprietà specificata all'oggetto PropertyMap.

Apply(String)

Esegue il traduttore di proprietà per la proprietà specificata, in base al valore della proprietà corrente dell'oggetto di origine.

ApplyAll()

Esegue il traduttore di proprietà per ogni proprietà mappata, in base ai valori correnti della proprietà dell'oggetto di origine.

Clear()

Rimuove tutti i mapping delle proprietà.

Contains(String)

Ottiene un valore che indica se viene eseguito il mapping della proprietà specificata.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
Remove(String)

Elimina la proprietà specificata dal mapping.

Reset(String)

Ripristina il mapping delle proprietà predefinito per la proprietà specificata.

ResetAll()

Ripristina i mapping delle proprietà predefiniti.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Eventi

Nome Descrizione
PropertyMappingError

Si verifica quando viene generata un'eccezione da un traduttore di proprietà.

Si applica a

Vedi anche