Share via


PropertyMap クラス

定義

Windows フォーム コントロールと 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
継承
PropertyMap
属性

次のコード例は、プロパティのマッピングをコントロールに Margin 追加する方法を 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

次のコード例は、コントロールのプロパティの既定のマッピングを FlowDirection 置き換える方法を WindowsFormsHost 示しています。

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

注釈

このクラスをPropertyMap使用して、ハイブリッド アプリケーションのWindows フォーム プロパティとWindows Presentation Foundation (WPF) プロパティ間の変換を定義します。 クラスElementHost.PropertyMapWindowsFormsHost.PropertyMapクラスのプロパティは、ElementHostWindowsFormsHostあるテクノロジから他のテクノロジへのマッピングを定義します。

詳細については、「 チュートリアル: ElementHost コントロールを使用したプロパティのマッピング 」および 「チュートリアル: WindowsFormsHost 要素を使用したプロパティのマッピング」を参照してください。

コンストラクター

PropertyMap()

PropertyMap クラスの新しいインスタンスを初期化します。

PropertyMap(Object)

指定されたソース オブジェクトを使用して、PropertyMap クラスの新しいインスタンスを初期化します。

プロパティ

DefaultTranslators

既定で定義されているプロパティ マッピングのコレクションを取得します。

Item[String]

特定のプロパティに関する PropertyTranslator デリゲートを取得または設定します。

Keys

PropertyMap コレクションのプロパティ名を格納している ICollection オブジェクトを取得します。

SourceObject

変換するプロパティを持つオブジェクトを取得します。

Values

PropertyMap コレクションにプロパティ トランスレーターが含まれる ICollection を取得します。

メソッド

Add(String, PropertyTranslator)

特定のプロパティに関する PropertyTranslator デリゲートを PropertyMap に追加します。

Apply(String)

ソース オブジェクトの現在のプロパティ値に基づいて、指定されたプロパティのプロパティ トランスレーターを実行します。

ApplyAll()

ソース オブジェクトの現在のプロパティ値に基づいて、マップされた各プロパティのプロパティ トランスレーターを実行します。

Clear()

プロパティ マッピングをすべて削除します。

Contains(String)

指定されたプロパティがマップされているかどうかを示す値を取得します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
Remove(String)

マッピングから指定されたプロパティを削除します。

Reset(String)

指定されたプロパティの既定のプロパティ マッピングを復元します。

ResetAll()

既定のプロパティ マッピングを復元します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

events

PropertyMappingError

プロパティ トランスレーターによって例外が発生したときに発生します。

適用対象

こちらもご覧ください