Search code examples
wpfwindowhandle

Finding the handle to a WPF window


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.


Solution

  • 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.