Finding the handle to a WPF window Finding the handle to a WPF window wpf wpf

Finding the handle to a WPF window


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.


Just use your window with the WindowsInteropHelper class:

// ... Window myWindow = get your Window instance...IntPtr windowHandle = new WindowInteropHelper(myWindow).Handle;

Right now, you're asking for the Application's main window, of which there will always be one. You can use this same technique on any Window, however, provided it is a System.Windows.Window derived Window class.


you can use :

Process.GetCurrentProcess().MainWindowHandle