AddOwnedForm - 添加 WPF 窗口?

发布于 2024-09-14 17:46:13 字数 275 浏览 1 评论 0原文

我正在使用现有的 WinForms 表单。我正在尝试与它连接一个新的 WPF 窗口(以替换旧表单)。旧代码称为 mainForm.AddOwnedForm(newForm);

我知道这使得新窗体在某种程度上成为主窗体的子窗体——当主窗体隐藏时,它是隐藏的,等等。

有没有办法让我以同样的方式将 WPF 窗口链接到主窗体?

显然,WinForms 不了解 WPF,因此我不期望使用 AddOwnedWindow 方法或任何其他方法。但是有没有办法模拟这个功能呢?

I'm working with an existing WinForms form. I'm trying to interface a new WPF Window with it (to replace an old form). The old code called mainForm.AddOwnedForm(newForm);.

I know that that makes the new form somewhat of a child of the main form -- it's hidden when the main form is, etc.

Is there a way for me to link a WPF window to the main form in the same way?

Obviously, WinForms doesn't know about WPF, so I'm not expecting an AddOwnedWindow method or anything. But is there a way to emulate this functionality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-09-21 17:46:13

我想通了。

WindowInteropHelper 会做到这一点:

var newWindow = new WPFWindow();
var helper = new WindowInteropHelper(newWindow) {Owner = mainForm.Handle};

感谢

I figured it out.

WindowInteropHelper will do it:

var newWindow = new WPFWindow();
var helper = new WindowInteropHelper(newWindow) {Owner = mainForm.Handle};

Thanks to this source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文