Wpf窗口在winform之上停留(不需要) [英] Wpf window stays (unwanted) on top of winform

查看:103
本文介绍了Wpf窗口在winform之上停留(不需要)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我们有一个相当大的Windows窗体应用程序。

现在我们要在Windows窗体应用程序中逐步开发WPF窗口中的新功能。

一切正常,但WPF窗口始终位于较旧的WinForm窗口之上。

并且无法将激活的WinForm窗口拖到顶部WPF窗口。

两者都不是模态形式,因此我们的用户需要能够将一个WinForm放在WPF窗口之上,在WinForm和WPF窗口之间切换。



我怀疑它与我的Windows窗体应用程序中的MdiParent有关,而且你无法将WPF窗口设置为该MdiParent?



我们非常感谢任何帮助!



谢谢,

Sarah



我尝试了什么:



这是一个WPF窗口,在本例中为frmArchiefonderdeel,是叫:



Hi
We have a rather big Windows Forms Application.
Now we want to gradually develop new features in WPF windows, within our Windows Forms Application.
Everything works fine, except that the WPF windows are always on top of the older WinForm windows.
And it is impossible to drag an activated WinForm window on top of a WPF window.
Both are not modal forms, so our users need to be able to put one WinForm on top of the WPF window, switching between the WinForm and the WPF window.

I suspect it has something to do with the MdiParent I have in my Windows Forms Application and the fact that you can not set a WPF window to that MdiParent??

Any help would be much appreciated!

Thanks,
Sarah

What I have tried:

This is how a WPF window, in this example frmArchiefonderdeel, is called:

Dim oFrmArchiefOnderdeel As New frmArchiefonderdeel With {.oSharedData = oSharedData}
   oFrmArchiefOnderdeel.Show(Me)




<Extension()> Public Sub Show(wn As Windows.Window, owner As Windows.Forms.Form)
   BMFUtility.SetOwner(owner, wn)
   ElementHost.EnableModelessKeyboardInterop(wn)

   AddHandler wn.Closed, AddressOf WindowClosed

   wn.ShowInTaskbar = False
   wn.Show()
End Sub




Public Shared Sub SetOwner(owner As System.Windows.Forms.Form, wpfWindow As System.Windows.Window)
   Dim helper As New WindowInteropHelper(wpfWindow)
   helper.Owner = owner.Handle
End Sub





这是一个较老的WinForm,在本例中为frmBDGMonitor,被称为:



And this is how an older WinForm, in this example frmBDGMonitor, is called:

Dim oFrmBDGMonitor As frmBDGMonitor
oFrmBDGMonitor = New frmBDGMonitor
oFrmBDGMonitor.ShowInTaskbar = False
oFrmBDGMonitor.MdiParent = Me
oFrmBDGMonitor.Show()

推荐答案

这里有两个重要的注释:



1. WPF / WinForm互操作非常敏感 - 它可以难以获得完整的预期行为。



2. WPF不支持MDI,因此您可能会尝试使用WPI与MDI互操作时出现不兼容问题。



我建议从迁移的角度来看,在WPF中为应用程序构建新的核心部分并使用WinForms互操作。 MDI本身也从UI的角度出发,所以无论如何我都会加入这个趋势。



另一个问题是,如果你是不首先在WPF中构建核心,当你开始完成迁移时,会出现大量的冲突和冗余。



除此之外,在迁移期间你应该适应现代复合应用程序开发,所以你的shell和框架应该是基于WPF的。



祝你好运!
Two important notes here:

1. The WPF/WinForm interop is very touchy - it can be difficult to get the complete expected behavior.

2. WPF does not support MDI so you may incompatibility issues trying to use WPF interop with MDI.

What I would recommend from a migration standpoint is to build the new core pieces to the application in WPF and use the WinForms interop. MDI itself has kind of been shunned from the UI perspective too, so I'd jump on board with that trend anyway.

The other problem is, if you're not building your core in WPF first there's going to be a slew of conflict and redundancy when you start getting through your migration.

In addition to that, during the migration you should be adapting modern composite application development so your shells and frameworks should be WPF based.

Good luck!


这篇关于Wpf窗口在winform之上停留(不需要)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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