Open WinForm from WPF application?

Generally you need to host your form in a WindowInteropHelper, like following in the WPF window Button.Click event handler:

C#:

private void button1_Click(object sender, RoutedEventArgs e) {
  Form1 form = new Form1();
  WindowInteropHelper wih = new WindowInteropHelper(this);
  wih.Owner = form.Handle;
  form.ShowDialog();
}

VB:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
    Dim form As New Form1()
    Dim wih As New WindowInteropHelper(Me)
    wih.Owner = Form.Handle
    form.ShowDialog()
End Sub

And of course you need to add reference/import of your project and System.Windows.Forms.dll

Tags:

.Net

Winforms

Wpf