閱讀英文

共用方式為


WindowsFormsHost.PropertyMap 屬性

定義

取得屬性對應,以此判斷 WindowsFormsHost 項目上的設定屬性如何影響所裝載的 Windows Forms 控制項。

public System.Windows.Forms.Integration.PropertyMap PropertyMap { get; }

屬性值

PropertyMap

PropertyMap 會將屬性對應 WindowsFormsHost 至裝載Windows Forms控制項上的屬性。

範例

下列程式碼範例示範如何將 屬性的 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;
}

備註

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

適用於

另請參閱