Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winform dialog with WPF window as Parent

Tags:

winforms

wpf

I have a WinForm dialog and I want to set its Parent property to a WPF window. How can I do this?

like image 521
Miklós Balogh Avatar asked Oct 19 '11 13:10

Miklós Balogh


1 Answers

Consider passing parameter to ShowDialog method instead of using Parent property.

You can write helper class

class Wpf32Window : IWin32Window
{
  public IntPtr Handle { get; private set; }

  public Wpf32Window(Window wpfWindow)
  {
    Handle = new WindowInteropHelper(wpfWindow).Handle;
  }
}

public static class WindowExtensions
{
  public static IWin32Window GetWin32Window (this Window parent)
  {
    return new Wpf32Window(parent);
  }
}

After that you can just write

winFormsWindow.Show(yourWpfWindow.GetWin32Window());
like image 77
nevermind Avatar answered Nov 20 '22 14:11

nevermind