在 Windows 10 (1803) 上,如果 WPF 透明窗口覆盖所有应用程序,则所有应用程序都将失去联系或触笔



如果我使用如下所示的代码创建一个简单的空窗口的新 WPF 应用程序,我发现 WPF 应用程序涵盖的所有应用程序都失去了联系或触笔反应。这只能在 Windows 10 升级到 1803 (10.0.17134.0) 时重现。

<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" Background="Transparent"
Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>

我编写了另一个 WPF 应用程序来了解发生了什么。因此,我将一个 StylusDown 事件添加到 Window,如下所示的代码:

// This code is in another WPF application.
private void OnStylusDown(object sender, StylusDownEventArgs e)
{
// Set a breakpoint here.
}

但是在我关闭顶部的透明 WPF 窗口之前,断点从未到达。

我将非常简单的代码推送到 GitHub:dotnet-campus/TouchIssueOnWindows10.0.17134。克隆它可能会有所帮助。

为什么会发生这种情况以及如何解决?任何回复不胜感激。

已更新

Microsoft已在.NET Framework 2018 年 8 月质量汇总预览版中修复了此问题。

  • 2018 年 8 月 30 日 - KB4346783(操作系统内部版本 17134.254)

解决了在具有透明覆盖窗口的 Windows 演示文稿基础 (WPF) 应用程序中以不同方式处理触摸和鼠标事件的问题。


源语言

经过整整一周的调试,我终于找到了解决方案。

只需为窗口添加一个ResizeMode="NoResize"属性,如下所示的代码:

<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>

@lindexi已将此问题和此解决方案发布到他的帖子中。如果需要有关此问题的详细信息,请阅读 win10 17025 触摸错误 - lindexi 了解更多详细信息。(这篇文章是用多种语言写的,所以即使你忽略未知字符,你也不会错过任何东西。

实际上,我仍然无法弄清楚为什么此属性有所帮助。

谁能解释这个问题的原因?

最新更新