Share via


PropertyMap 클래스

정의

Windows Forms 컨트롤 및 WPF(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
상속
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 Forms 속성과 WPF(Windows Presentation Foundation) 속성 간의 변환을 정의합니다. 클래스 및 WindowsFormsHost.PropertyMap WindowsFormsHost 클래스의 ElementHost 속성은 ElementHost.PropertyMap 한 기술에서 다른 기술로의 매핑을 정의합니다.

자세한 내용은 연습: ElementHost 컨트롤을 사용하여 속성 매핑연습: WindowsFormsHost 요소를 사용하여 속성 매핑을 참조하세요.

생성자

PropertyMap()

PropertyMap 클래스의 새 인스턴스를 초기화합니다.

PropertyMap(Object)

지정된 소스 개체를 사용하여 PropertyMap 클래스의 새 인스턴스를 초기화합니다.

속성

DefaultTranslators

기본적으로 정의된 속성 매핑의 컬렉션을 가져옵니다.

Item[String]

지정된 속성의 PropertyTranslator 대리자를 가져오거나 설정합니다.

Keys

ICollection 컬렉션의 값이 포함된 PropertyMap 개체를 가져옵니다.

SourceObject

변환할 속성이 있는 개체를 가져옵니다.

Values

ICollection 컬렉션의 속성 변환기가 포함된 PropertyMap 을 가져옵니다.

메서드

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)

이벤트

PropertyMappingError

속성 변환기에 의해 예외가 발생하는 경우에 발생합니다.

적용 대상

추가 정보