PropertyMap Klas

Definitie

Biedt een manier om eigenschapswaarden tussen Windows Forms besturingselementen en Windows Presentation Foundation (WPF) elementen te vertalen.

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
Overname
PropertyMap
Kenmerken

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u een toewijzing voor de Margin eigenschap toevoegt aan een ElementHost besturingselement.

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

In het volgende codevoorbeeld ziet u hoe u de standaardtoewijzing voor de FlowDirection eigenschap in een WindowsFormsHost besturingselement vervangt.

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

Opmerkingen

Gebruik de klasse PropertyMap om vertalingen te definiëren tussen Windows Forms eigenschappen en Windows Presentation Foundation -eigenschappen (WPF) in een hybride toepassing. De ElementHost.PropertyMap en WindowsFormsHost.PropertyMap eigenschappen van de en klassen definiëren toewijzingen van de ElementHost ene WindowsFormsHost technologie naar de andere.

Zie Walkthrough: Toewijzingseigenschappen met het ElementHost-besturingselement en walkthrough: toewijzingseigenschappen met behulp van het ElementFormsHost-element voor meer informatie.

Constructors

Name Description
PropertyMap()

Initialiseert een nieuw exemplaar van de PropertyMap klasse.

PropertyMap(Object)

Initialiseert een nieuw exemplaar van de PropertyMap klasse met het opgegeven bronobject.

Eigenschappen

Name Description
DefaultTranslators

Hiermee haalt u een verzameling eigenschapstoewijzingen op die standaard worden gedefinieerd.

Item[String]

Hiermee haalt u de PropertyTranslator gemachtigde voor de opgegeven eigenschap op of stelt u deze in.

Keys

Hiermee haalt u een ICollection object op met de eigenschapsnamen in de PropertyMap verzameling.

SourceObject

Hiermee haalt u het object op dat de eigenschappen bevat die moeten worden vertaald.

Values

Hiermee haalt u een ICollection met de eigenschapvertalers in de PropertyMap verzameling op.

Methoden

Name Description
Add(String, PropertyTranslator)

Voegt een PropertyTranslator gemachtigde voor de opgegeven eigenschap toe aan de PropertyMap.

Apply(String)

Hiermee wordt de eigenschapvertaler voor de opgegeven eigenschap uitgevoerd op basis van de huidige eigenschapswaarde van het bronobject.

ApplyAll()

Hiermee wordt de eigenschapvertaler uitgevoerd voor elke toegewezen eigenschap, op basis van de huidige eigenschapswaarden van het bronobject.

Clear()

Hiermee verwijdert u alle eigenschapstoewijzingen.

Contains(String)

Hiermee wordt een waarde opgehaald die aangeeft of de opgegeven eigenschap is toegewezen.

Equals(Object)

Bepaalt of het opgegeven object gelijk is aan het huidige object.

(Overgenomen van Object)
GetHashCode()

Fungeert als de standaardhashfunctie.

(Overgenomen van Object)
GetType()

Hiermee haalt u de Type huidige instantie op.

(Overgenomen van Object)
MemberwiseClone()

Hiermee maakt u een ondiepe kopie van de huidige Object.

(Overgenomen van Object)
Remove(String)

Hiermee verwijdert u de opgegeven eigenschap uit de toewijzing.

Reset(String)

Hiermee herstelt u de standaardeigenschapstoewijzing voor de opgegeven eigenschap.

ResetAll()

Hiermee worden de standaardeigenschapstoewijzingen hersteld.

ToString()

Retourneert een tekenreeks die het huidige object vertegenwoordigt.

(Overgenomen van Object)

gebeurtenis

Name Description
PropertyMappingError

Treedt op wanneer een uitzondering wordt gegenereerd door een eigenschapvertaler.

Van toepassing op

Zie ook