Finding the handle to a WPF window

Evan picture Evan · Oct 12, 2009 · Viewed 102k times · Source

Windows forms had a property win1.Handle which, if I recall, returns the handle of the main window handle?

Is there an equivalent way to get the handle of a WPF Window?

I found the following code online,

IntPtr windowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle;

but I don't think that will help me because my application has multiple windows.

Thanks!!

Answer

Gregory Higley picture Gregory Higley · Oct 12, 2009

Well, instead of passing Application.Current.MainWindow, just pass a reference to whichever window it is you want: new WindowInteropHelper(this).Handle and so on.