WPF 与 Winforms 中的窗口透明度
为什么我必须在 WPF 表单上将 WindowStyle
属性设置为 None
才能获得透明度,但在 Winforms 中我可以在任何表单上执行此操作,并保留边框,标准按钮等?显然 API 支持这一点,所以我不清楚 WPF 有什么特殊之处会导致这个问题。
我猜测 WPF 正在跳过一些 DirectX 或 OpenGL 的障碍,而 Winforms 只是通过 API 设置窗口的 alpha,但我可能大错特错了。
Why is it that I have to set the WindowStyle
property to None
on a WPF form to get transparency, but in Winforms I can do it on any form, and retain borders, standard buttons, etc? Clearly the API supports this, so I'm not clear on what's special about WPF that would make this an issue.
I'm guessing that WPF is jumping through some DirectX or OpenGL hoops, while Winforms is just setting the alpha for the window via the API, but I could be way off base.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同意,这很严厉:
WPF 使用与 Windows 窗体(分层窗口)完全相同的机制来实现这一点。没有明显的理由表明它在 WPF 中不能以同样的方式工作。从 Window.cs 中提取的代码片段简单地排除了这一点。然而,UsesPerPixelOpacity 属性有一个提示:
当您启用每像素不透明度时,系统不再绘制非客户区域。这是因为 UsesPerPixelOpacity 的预期目的是显示在互操作场景中工作的非矩形顶级 UI,而显示矩形非客户区域违背了该目的。
我猜是“互操作场景”。
Agreed, this is heavy handed:
WPF uses the exact same mechanism to implement this as Windows Forms, layered windows. There is no obvious reason it wouldn't work the same way in WPF. The code snippet, lifted from Window.cs, simply rules it out. There is however one hint from the UsesPerPixelOpacity property:
When you enable per-pixel opacity, the system no longer draws the non-client area. This is because the intended purpose of UsesPerPixelOpacity is to show non-rectangular top-level UI that works in interoperation scenarios, and showing the rectangular non-client area defeats that purpose.
"interoperation scenarios", I guess.