将 WPF 窗口附加到桌面
我创建了一个没有镶边和透明背景的 WPF 应用程序
WindowStyle="None" AllowsTransparency="True"
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
IntPtr oldParent = SetParent(windowHandle, desktopHandle);
,但是每当我尝试将此窗口设置为桌面进程的子窗口时(这样它就不会受到“显示桌面”命令的影响) 它停止绘制。如果我将AllowsTransparency 更改回False,它会按预期工作,但我确实希望它是透明的并且没有边框。
任何人都可以给我一些关于如何使这项工作正确进行的建议吗?我可以通过在 Winforms 应用程序中使用相同的方法来使其工作。
I have created a WPF application that has no chrome and a transparent background
WindowStyle="None" AllowsTransparency="True"
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
IntPtr oldParent = SetParent(windowHandle, desktopHandle);
But whenever i try to set this window to be a child of the desktop process (So that it isn't affected by "Show Desktop" commands) it stops drawing. If i change AllowsTransparency back to False it works as expected, however I do want it to be transparent and have no borders.
Can anyone give me any suggestions on how to make this work correctly? I can get this to work by using the same method in a Winforms application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑它适用于 Winforms 而不适用于 WPF 的原因是 Winforms 使用 GDI 进行渲染,而 WPF 使用 DirectX。这些技术存在互操作性问题,这些问题在此处有更全面的详细说明,特别是在名为“透明度和顶级窗口”的部分中。
http://msdn.microsoft.com/en-us/library/aa970688.aspx
您也许可以通过在 Win32 窗口中托管 WPF 视觉对象来解决该问题,详细信息如下:
http://msdn.microsoft.com/en-us/library/ms742522.aspx #hosting_a_wpf_page
I suspect that the reason it worked for Winforms and not for WPF is that Winforms uses GDI for rendering and WPF uses DirectX. These technologies have interoperability issues that are more fully detailed here, in particular in a section called "Transparency and Top-Level Windows".
http://msdn.microsoft.com/en-us/library/aa970688.aspx
You might be able work around the issue by hosting the WPF visual in a Win32 window, as detailed here:
http://msdn.microsoft.com/en-us/library/ms742522.aspx#hosting_a_wpf_page