且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我无法通过 VNC 看到 WPF Windows 应用程序的上下文菜单

更新时间:2023-10-11 12:31:52

我没有阅读/发现任何有关通过远程连接查看 WPF 应用程序的已知问题.但是,如果您考虑如何远程连接工作,我想对问题进行一些猜测,甚至可能是一个解决方案.

I have not read/found any known issue regarding viewing WPF applications across a remote connection. However if you think about how remote connections work I would like hazard a few guesses to the problem and even maybe a solution.

当您安装任何远程桌面软件时,您实际上会做两件事:设置中继器以中继输入命令和添加充当帧服务器的显示适配器,即,而不是输出内容屏幕到监视器它通过网络发送信息.

When you install any remote desktop software you really doing two things: setting up a repeater to relay input commands and adding a display adapter that acts as a frame server, i.e., instead of outputting the contents of the screen to a monitor it sends the information over the network.

如您所知,WPF 使用 DirectX 来加速其渲染(受 GPU 限制),但遗憾的是,所有显卡加速都无法通过远程桌面连接工作.

As you know, WPF utilises DirectX to accelerate its rendering (GPU bound) and it is an unfortunate limitation that all graphic card acceleration does not work via remote desktop connection.

我认为在您的特定情况下发生的事情是,WPF 在尝试绘制上下文菜单时不会退回到使用它的软件渲染管道 - 可能是因为上下文菜单是一个 Popup 和在单独的可视化树中.

What I believe is happening in your specific case is that WPF is not falling back to using it's software rendering pipeline when it attempts to draw the context menu - perhaps because the context menu is a Popup and in a separate visual tree.

值得尝试的是强制您的 WPF 应用程序使用软件渲染.

Something worth trying would be to force your WPF application to use software rendering.

void OnLoaded(object sender, EventArgs e)
{
    HwndSource hwndSource = (HwndSource)PresentationSource.FromVisual(this);
    HwndTarget hwndTarget = hwndSource.CompositionTarget;

    hwndTarget.RenderMode = RenderMode.SoftwareOnly;
}

如果确实如此,您有两种选择:强制 WPF 使用软件渲染管道或尝试部署 高性能远程桌面访问软件来自惠普的解决方案.

If this does prove to be the case, you have two options: force WPF to use software rendering pipeline or try deploying a high-performance remote desktop access software solution from Hewlett Packard.

HTH,

参考资料
- 微软关于解决 WPF 中图形问题的指南.
- 硬件WPF 中的加速
- 惠普远程图形软件

更新:对于搜索并找到此答案的其他人,您需要更改 VNC 客户端设置以启用 alpha 混合.正如@mcdrewski 所指出的,默认情况下 VNC 不会检测/渲染 alpha 混合窗口.启用 alpha 混合会产生成本,您会注意到 VNC 客户端有点滞后.

Update: For others searching and finding this answer, you need change a VNC client setting to enable alpha blending. As noted by @mcdrewski that by default VNC won't detect/render alpha blended windows. Enabling alpha blending incurs a cost and you will notice the VNC client lag a bit.