次の方法で共有


PropertyMap.Add(String, PropertyTranslator) メソッド

定義

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

public:
 void Add(System::String ^ propertyName, System::Windows::Forms::Integration::PropertyTranslator ^ translator);
public void Add (string propertyName, System.Windows.Forms.Integration.PropertyTranslator translator);
member this.Add : string * System.Windows.Forms.Integration.PropertyTranslator -> unit
Public Sub Add (propertyName As String, translator As PropertyTranslator)

パラメーター

propertyName
String

マップするプロパティの名前。

translator
PropertyTranslator

propertyName の変更時に呼び出される PropertyTranslator デリゲート。

例外

propertyName には既存のマッピングがあります。

次のコード例は、 プロパティのマッピング 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

次のコード例は、 プロパティのマッピング Clip をコントロールに追加する方法を WindowsFormsHost 示しています。

// The AddClipMapping method adds a custom 
// mapping for the Clip property.
private void AddClipMapping()
{
    wfHost.PropertyMap.Add(
        "Clip",
        new PropertyTranslator(OnClipChange));
}

// The OnClipChange method assigns an elliptical clipping 
// region to the hosted control's Region property.
private void OnClipChange(object h, String propertyName, object value)
{
    WindowsFormsHost host = h as WindowsFormsHost;
    System.Windows.Forms.CheckBox cb = host.Child as System.Windows.Forms.CheckBox;

    if (cb != null)
    {
        cb.Region = this.CreateClipRegion();
    }
}

// The Window1_SizeChanged method handles the window's 
// SizeChanged event. It calls the OnClipChange method explicitly 
// to assign a new clipping region to the hosted control.
private void Window1_SizeChanged(object sender, SizeChangedEventArgs e)
{
    this.OnClipChange(wfHost, "Clip", null);
}

// The CreateClipRegion method creates a Region from an
// elliptical GraphicsPath.
private Region CreateClipRegion()
{   
    GraphicsPath path = new GraphicsPath();

    path.StartFigure(); 

    path.AddEllipse(new System.Drawing.Rectangle( 
        0, 
        0, 
        (int)wfHost.ActualWidth, 
        (int)wfHost.ActualHeight ) );

    path.CloseFigure(); 

    return( new Region(path) );
}
' The AddClipMapping method adds a custom mapping 
' for the Clip property.
Private Sub AddClipMapping()

    wfHost.PropertyMap.Add( _
        "Clip", _
        New PropertyTranslator(AddressOf OnClipChange))

End Sub

' The OnClipChange method assigns an elliptical clipping 
' region to the hosted control's Region property.
Private Sub OnClipChange( _
ByVal h As Object, _
ByVal propertyName As String, _
ByVal value As Object)

    Dim host As WindowsFormsHost = h

    Dim cb As System.Windows.Forms.CheckBox = host.Child

    If cb IsNot Nothing Then
        cb.Region = Me.CreateClipRegion()
    End If

End Sub

' The Window1_SizeChanged method handles the window's 
' SizeChanged event. It calls the OnClipChange method explicitly 
' to assign a new clipping region to the hosted control.
Private Sub Window1_SizeChanged( _
ByVal sender As Object, _
ByVal e As SizeChangedEventArgs)

    Me.OnClipChange(wfHost, "Clip", Nothing)

End Sub

' The CreateClipRegion method creates a Region from an
' elliptical GraphicsPath.
Private Function CreateClipRegion() As [Region] 
    Dim path As New GraphicsPath()
    
    path.StartFigure()
    
    path.AddEllipse(New System.Drawing.Rectangle( _
        0, _
        0, _
        wfHost.ActualWidth, _
        wfHost.ActualHeight))
    
    path.CloseFigure()
    
    Return New [Region](path)

End Function

注釈

を設定するときに、 に propertyNameが存在しないPropertyTranslator場合、新しいデリゲートが にPropertyMap追加されます。 の が PropertyTranslator 既に存在する propertyName場合は、 InvalidOperationException が発生します。

適用対象

こちらもご覧ください