ElementHost.PropertyMap 屬性

定義

取得屬性對應,這個對應會決定控制項上 ElementHost 設定屬性如何影響裝載Windows Presentation Foundation (WPF) 專案。

public:
 property System::Windows::Forms::Integration::PropertyMap ^ PropertyMap { System::Windows::Forms::Integration::PropertyMap ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Integration.PropertyMap PropertyMap { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PropertyMap : System.Windows.Forms.Integration.PropertyMap
Public ReadOnly Property PropertyMap As PropertyMap

屬性值

PropertyMap 對應 ElementHost 至託管 WPF 專案上的屬性。

屬性

範例

下列程式碼範例示範如何使用 PropertyMap 屬性來轉譯 Margin 託管 WPF 專案的 屬性。 如需詳細資訊,請參閱 逐步解說:使用 ElementHost 控制項對應屬性

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

備註

Windows Forms和 WPF 技術有兩種類似但不同的屬性模型。 屬性對應 支援兩個架構之間的互通。 如需詳細資訊,請參閱 Windows Form 和 WPF 屬性對應

適用於

另請參閱