WPF C# 触摸在第 11 次触摸之前无法工作

问题描述 投票:0回答:2

我已经制作了一个自助服务应用程序,一个 KIOSK 应用程序。产品列表以编程方式生成。在每个窗口上,该程序在触摸屏上都能正常运行。除了一个窗口,我必须准确触摸 10 次才能开始工作。我试图重新制作那个窗口,我只在上面放了一个按钮,但它是一样的。如果我禁用手写笔和触摸支持:

<AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true"/>
比它有效。但这会禁用触摸滚动,而这对于良好的用户体验是必需的。 如果我使用触地或类似的东西,它会起作用,但是我在该窗口上有
CheckBox
RadioButton
,并且我无法捕获它们上的任何触摸事件。有什么想法吗?

即使我清除代码中的所有内容,或者创建一个具有相同名称的新窗口,它也不起作用...

这是我的 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>

我的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();
c# wpf scroll touch stylus
2个回答
1
投票

我面临着一模一样的情况。我发现罪魁祸首是

window.ShowDialog()
。如果您尝试,只是为了测试,只需使用
window.Show()
就可以了。 在我看来,由于调用线程被阻塞在
window.ShowDialog()
上,因此与触摸相关的事件不会被处理/重新路由。用鼠标就可以正常工作。 目前,我没有找到解决方案,只是一种解决方法(一个烦人的方法): 当我显示新窗口时,之前我在新窗口上设置
Topmost=true
,在父窗口上设置
Topmost=false
。我还在新窗口上设置了调用者的所有者,因此我可以在关闭新窗口之前将所有者 Topmost 设置为 true。


0
投票

将触地事件与点击事件一起使用。它解决了触摸问题。

© www.soinside.com 2019 - 2024. All rights reserved.