Search code examples
c#wpfwinformsshowdialogwinforms-interop

Minimizing a WPF window owned by a Winform is not working as expected


I have a Form control named MyForm, which is the parent of some WPF BaseWindow, named MyWindow.

I'm setting their relationship as follows:

new WindowInteropHelper(myWindowInstance).Owner = myFormInstance.Handle;

And am showing the window using

myWindowInstance.ShowDialog();

The window is set with

ResizeMode="CanResize"

Therefor, it has a minimize button. On minimizing the window, its not minimized as expected, but rather minimized to the bottom of the form.

What I would like to experience is that the parent would be minimized as well. Meaning that minimizing the window, will be translated to minimizing the form.


Solution

  • You probably want to create event handlers to control their behavior relationship when events (minimize) occurred.

    For WPF, you could use Window_StateChanged event with checking if this.WindowState == WindowState.Minimized

    Then for the WinForm you could do the trick by Resize event and checking if WindowState == FormWindowState.Minimized

    If any of these is true, then you could minimize both.