Finding the handle to a WPF window

前端 未结 4 1388
庸人自扰
庸人自扰 2020-11-30 00:19

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 Wind

4条回答
  •  既然无缘
    2020-11-30 00:47

    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.

提交回复
热议问题