How to put a custom windows forms control in a WPF application?

前端 未结 3 1275
不思量自难忘°
不思量自难忘° 2021-01-01 02:18

As a short term solution I\'m trying to jam a windows form \'usercontrol\' into a WPF application. I see in the WPF application view that I can add a \'custom windows form

3条回答
  •  自闭症患者
    2021-01-01 02:33

    Add a reference to System.Windows.Forms and WindowsFormsIntegration to your Project

    xmlns:WinForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns:WindowsFormsIntegration="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
    

    And place Windows forms host in the window.

      
                    
      
    

    Now in C# code

    using Forms = System.Windows.Forms;
    .........................
    Forms.FlowLayoutPanel flpPanel = this.wfhDate.Child as Forms.FlowLayoutPanel;
    // Initialize your Forms contol here.
    flpPanel.Controls.Add( yourControl );
    

提交回复
热议问题