将WinForms表单设置为WPF窗口的所有者 [英] Setting a WinForms Form as Owner for a WPF Window

查看:48
本文介绍了将WinForms表单设置为WPF窗口的所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个围绕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?

推荐答案

您可以使用在Winform Form 的主窗体中使用以上代码.要显示WPF窗口时,请记住添加必需的引用: PresentationCode PresentationFramework WindowsBase .

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆