将WinForms表单设置为WPF窗口的所有者 [英] Setting a WinForms Form as Owner for a WPF Window
问题描述
我有一个围绕System.Windows.Forms.Form构建的主应用程序.用户可以调用一个遗留的System.Windows.Window,将其设置为Topmost.我希望Window由主应用程序拥有,因此在最小化应用程序时它将最小化.所以我期望的代码是
I have a main application which is built around a System.Windows.Forms.Form There is a legacy System.Windows.Window that the user can call up which is set as Topmost. I would like the Window to be owned by the main application, so it will minimize when the application is minimized. So my expected code was
TopmostDisplayWindow.Owner = MainAppForm;
但是,没有使用Form的Window.Owner方法,并且Window没有覆盖拥有所有者的Show().
However, there is no Window.Owner method that takes a Form and Window has no override of Show() that takes the owner.
是否有一种简便的方法来获取MainAppForm的窗口,还是需要更复杂的方法?
Is there an easy way to get a Window for the MainAppForm or would it take something more complicated?
推荐答案
Use the above code in your main form that is a Winform Form
.
Remember to add required references when you want to show your WPF Window: PresentationCode
, PresentationFramework
, WindowsBase
.
这篇关于将WinForms表单设置为WPF窗口的所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!