WPF C# 触摸在第 11 次触摸之前不起作用
我已经制作了一个用于自助服务的应用程序,一个 KIOSK 应用程序。产品列表以编程方式生成。在每个窗口上,该程序在触摸屏上都能正常运行。除了一个窗口,我必须准确触摸 10 次才能开始工作。我试图重新制作那个窗口,我只在上面放了一个按钮,但它是一样的。如果我禁用手写笔和触摸支持:
比它有效。但这会禁用触摸滚动,而这对于良好的用户体验是必需的。 如果我使用触地或类似的东西,它可以工作,但是我在该窗口上有 CheckBox
和 RadioButton
,并且我无法捕获它们上的任何触摸事件。有什么想法吗?
即使我清除代码中的所有内容,或者创建一个同名的新窗口,它也不起作用...
这是我的窗口 xml:
<Window x:Class="GestbalSelfSalePOS.ProdusComandaDetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GestbalSelfSalePOS"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="ProdusComandaDetailsWindow">
<Grid>
<Button Click="BackButton_Click" Content="Button" Margin="120"/>
</Grid>
</Window>
我的 CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace GestbalSelfSalePOS
{
/// <summary>
/// Interaction logic for ProdusComandaDetailsWindow.xaml
/// </summary>
public partial class ProdusComandaDetailsWindow : Window
{
public ProdusComandaDetailsWindow()
{
InitializeComponent();
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
这就是我打开此窗口的方式:
new ProdusComandaDetailsWindow().ShowDialog();
I've made an application, for self service, a KIOSK app. The product list is generated programmatically. On every window the program works fine on touch screen. Except for one window, where I have to touch exactly 10 times before it starts to work. I've tried to remake that window, I've put only one button on it, but it's the same. If i disable stylus and touch support with:<AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true"/>
than it works. But this disables touch scrolling which is necessary for good user experience.
If i use touchdown or something similar it works, but I have CheckBox
and RadioButton
on that window, and I couldn't catch any Touch event on them. Any ideas?
Even if I clean everything from my code, or I create a new window with the same name, it doesn't work...
This is my windows xml:
<Window x:Class="GestbalSelfSalePOS.ProdusComandaDetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GestbalSelfSalePOS"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="ProdusComandaDetailsWindow">
<Grid>
<Button Click="BackButton_Click" Content="Button" Margin="120"/>
</Grid>
</Window>
My CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace GestbalSelfSalePOS
{
/// <summary>
/// Interaction logic for ProdusComandaDetailsWindow.xaml
/// </summary>
public partial class ProdusComandaDetailsWindow : Window
{
public ProdusComandaDetailsWindow()
{
InitializeComponent();
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
This is how I open this window:
new ProdusComandaDetailsWindow().ShowDialog();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我面临着完全相同的情况。我发现罪魁祸首是window.ShowDialog()。如果您尝试,只是为了测试,只需使用
window.Show()
即可。在我看来,由于调用线程在 window.ShowDialog() 上被阻塞,因此与触摸相关的事件不会被处理/重新路由。用鼠标就可以正常工作。
目前,我没有找到解决方案,只是一种解决方法(一个烦人的方法):
当我显示新窗口时,之前我在新窗口上设置了
Topmost=true
,在父窗口上设置了Topmost=false
。我还在新窗口上将所有者设置为调用者,因此我可以在关闭新窗口之前将所有者 Topmost 设置为 true。I'm facing exactly the same. I found out that the culprit is
window.ShowDialog()
. If you try, just for testing, use justwindow.Show()
it will work.It seems to me that, since the calling thread is blocked on the
window.ShowDialog()
, the events related to touch are not processed/reouted. It works ok with the mouse.Currently, I have found no solution, just a workaround (an annoying one):
When I show the new window, previously I set
Topmost=true
on the new window andTopmost=false
on the parent. I also set, the on the new window, the owner to the caller, so I may set the owner Topmost to true, before closing the new window.将触地事件与单击事件一起使用。它解决了触摸问题。
Use the touchdown event together with the click event. It fixes the touch problem.