WindowsFormsHost ZOrder
看起来 WindowsFormsHost 控件被设置为显示在顶部。有没有办法更改其 z 顺序,以允许同一窗口上的其他 WPF 控件在 WindowsFormsHost 控件之上可见?
It appears WindowsFormsHost control is set to display on top. Is there any way to change its z-order to allow other WPF controls on the same window to be visible on top of the WindowsFormsHost control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,不能,由于 winformshost 合成到 WPF 窗口的方式,它必须出现在顶部。
请参阅此处中的 z 顺序段落。
Unfortunately no, because of the way the winformshost is composited into a WPF window it must appear on top.
See the z-order paragraph from here.
你可以做一个小技巧。当您声明
WindowsFormsHost
时,它的父组件是第一个 HWND 组件。通常它是根窗口。因此,控件的剪辑区域是整个窗口。我将展示一个使用 WPFScrollViewer
的示例。在这种情况下,
Button
将超出ScrollViewer
范围。但是有一种方法可以创建“中间”HWND 项来剪辑ScrollViewer
上的WinForms
区域。只需将另一个WindowsFormsHost
与ElementHost
一起放置,如下所示:现在
Button
的剪辑区域是ElementHost
和WinForms
按钮
在滚动时将被其剪切。您还可以为ContentContol
创建ControlTemplate
并在需要时重用它。You can do a little trick. When you declare an
WindowsFormsHost
, it's parent is first HWND component. Usually it's root window. So, clip area for controls is whole window. I'll show an example with WPFScrollViewer
.In this case
Button
s will be out ofScrollViewer
bounds. But there's a way to create "intermediate" HWND item to clipWinForms
area overScrollViewer
. Just place anotherWindowsFormsHost
withElementHost
like below:Now clip area for
Button
s isElementHost
andWinForms
Button
s will be clipped by it on scrolling. Also you can createControlTemplate
forContentContol
and reuse it where you need it.