PropertyMap Klasse
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Bietet eine Möglichkeit zum Übersetzen von Eigenschaftswerten zwischen Windows Forms-Steuerelementen und WPF-Elementen (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
- Vererbung
-
PropertyMap
- Attribute
Beispiele
Im folgenden Codebeispiel wird gezeigt, wie Sie einem Steuerelement eine Zuordnung für die Margin Eigenschaft ElementHost hinzufügen.
// 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
Das folgende Codebeispiel zeigt, wie die Standardzuordnung für die FlowDirection Eigenschaft eines WindowsFormsHost Steuerelements ersetzt wird.
// 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
Hinweise
Verwenden Sie die PropertyMap Klasse, um Übersetzungen zwischen Windows Forms-Eigenschaften und WPF-Eigenschaften (Windows Presentation Foundation) in einer Hybridanwendung zu definieren. Die ElementHost.PropertyMap Eigenschaften und WindowsFormsHost.PropertyMap Eigenschaften der ElementHost Klassen WindowsFormsHost definieren Zuordnungen von einer Technologie zur anderen.
Weitere Informationen finden Sie unter Walkthrough: Mapping Properties Using the ElementHost Control and Walkthrough: Mapping Properties Using the WindowsFormsHost Element.
Konstruktoren
| Name | Beschreibung |
|---|---|
| PropertyMap() |
Initialisiert eine neue Instanz der PropertyMap-Klasse. |
| PropertyMap(Object) |
Initialisiert eine neue Instanz der PropertyMap Klasse mit dem angegebenen Quellobjekt. |
Eigenschaften
| Name | Beschreibung |
|---|---|
| DefaultTranslators |
Ruft eine Auflistung von Eigenschaftenzuordnungen ab, die standardmäßig definiert sind. |
| Item[String] |
Dient zum Abrufen oder Festlegen des PropertyTranslator Delegaten für die angegebene Eigenschaft. |
| Keys |
Ruft ein ICollection Objekt ab, das die Eigenschaftennamen in der PropertyMap Auflistung enthält. |
| SourceObject |
Ruft das Objekt ab, das die zu übersetzenden Eigenschaften aufweist. |
| Values |
Ruft einen ICollection mit den Eigenschaftenübersetzern in der PropertyMap Auflistung ab. |
Methoden
| Name | Beschreibung |
|---|---|
| Add(String, PropertyTranslator) |
Fügt der angegebenen Eigenschaft PropertyMapeinen PropertyTranslator Delegaten hinzu. |
| Apply(String) |
Führt den Eigenschaftenübersetzer für die angegebene Eigenschaft basierend auf dem aktuellen Eigenschaftswert des Quellobjekts aus. |
| ApplyAll() |
Führt den Eigenschaftenübersetzer für jede zugeordnete Eigenschaft basierend auf den aktuellen Eigenschaftswerten des Quellobjekts aus. |
| Clear() |
Entfernt alle Eigenschaftenzuordnungen. |
| Contains(String) |
Ruft einen Wert ab, der angibt, ob die angegebene Eigenschaft zugeordnet ist. |
| Equals(Object) |
Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht. (Geerbt von Object) |
| GetHashCode() |
Dient als Standardhashfunktion. (Geerbt von Object) |
| GetType() |
Ruft die Type der aktuellen Instanz ab. (Geerbt von Object) |
| MemberwiseClone() |
Erstellt eine flache Kopie der aktuellen Object. (Geerbt von Object) |
| Remove(String) |
Löscht die angegebene Eigenschaft aus der Zuordnung. |
| Reset(String) |
Stellt die Standardeigenschaftszuordnung für die angegebene Eigenschaft wieder her. |
| ResetAll() |
Stellt die Standardeigenschaftenzuordnungen wieder her. |
| ToString() |
Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt. (Geerbt von Object) |
Ereignisse
| Name | Beschreibung |
|---|---|
| PropertyMappingError |
Tritt auf, wenn eine Ausnahme von einem Eigenschaftenübersetzer ausgelöst wird. |