旋转我的三星平板电脑后,是什么导致 WPF 应用程序中的触摸输入被忽略?
我有一个 WPF 应用程序,正在 Samsung XE700T1A 平板电脑上测试。我没有其他平板电脑可以测试它。启动应用程序后,当我将平板电脑旋转到纵向模式时,我的 UI 元素停止响应触摸。再次旋转回横向后,他们继续忽略触摸,但第三次旋转回纵向后,触摸起作用。进一步的旋转似乎会产生不确定的结果。有时触摸有效,有时你必须不断旋转才能恢复。我发现初始序列偶尔会有变化,但大多数情况下它看起来非常一致。
为了缩小可能性范围,我创建了一个简单的 WPF 应用程序来演示该问题。下面是代码:
MainWindow.xaml
<Window x:Class="RotationBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="DisplayText"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="I'm happy." />
<Button Grid.Row="1"
Height="22"
Width="80"
Margin="0,0,0,20"
Click="OnButtonPress"
Content="Depress Me" />
</Grid>
</Window>
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OnButtonPress(object sender, RoutedEventArgs e)
{
DisplayText.Text = DateTime.UtcNow.Ticks.ToString();
}
}
这个简单的演示应用程序也托管 GitHub 上。
有谁知道是什么导致了这个问题?或者如何解决?任何人都可以重现这个问题吗?
I have a WPF app that I'm testing on a Samsung XE700T1A tablet. I have no other tablets to test it on. Upon launching the app, when I rotate the tablet to portrait mode, my UI elements stop responding to touch. They continue to ignore touch after rotating back to landscape again, but then after rotating a third time back to portrait, touch works. Further rotations seem to have indeterminate results. Sometimes touch works, sometimes you have to keep rotating to get it back. I have seen an occasional variation in that initial sequence, but for the most part it appears very consistent.
In order to narrow down the range of possibilities, I created a simple WPF app to demonstrate the issue. Here is the code:
MainWindow.xaml
<Window x:Class="RotationBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="DisplayText"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="I'm happy." />
<Button Grid.Row="1"
Height="22"
Width="80"
Margin="0,0,0,20"
Click="OnButtonPress"
Content="Depress Me" />
</Grid>
</Window>
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OnButtonPress(object sender, RoutedEventArgs e)
{
DisplayText.Text = DateTime.UtcNow.Ticks.ToString();
}
}
This simple demo app is also hosted here on GitHub.
Does anyone know what is causing this issue? Or how to resolve it? Can anyone reproduce this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这显然是 Microsoft 内部已知的问题,其中“WPF 的触摸系统并不总是正确检测分辨率变化。”
解释那里的评论,解决方法是订阅
SystemEvents.DisplaySettingsChanged
并在短暂延迟后,将WM_DISPLAYCHANGE
重新发布到当前线程中标题为“SystemResourceNotifyWindow”的窗口。然而,那里发布的实际代码对于 Microsoft 以外的任何人来说都不实用。下面的代码适用于我们其他人。我已经在 GitHub 上发布了示例解决方案。
This is apparently an issue known internally at Microsoft where "WPF's touch system does not always detect resolution changes correctly."
Paraphrasing comments there, the workaround is to subscribe to
SystemEvents.DisplaySettingsChanged
and after a short delay, repostWM_DISPLAYCHANGE
to the window titled "SystemResourceNotifyWindow" in the current thread.However, the actual code posted there is not practical for anyone outside Microsoft. The code below will work for the rest of us. I've posted a sample solution here on GitHub.