Touch requires additional click

Sneeze

New member
Joined
Feb 10, 2023
Messages
1
Programming Experience
5-10
Hi

I have an application with a button list in a ItemsControl. The buttons use Command to invoke a method, that is binded to the button.

When using the mouse, the buttons work fine and the required methods are invoked.

When using touch, the buttons need to be double-clicked before a methods is invoked.

What is causing the difference in behaviour between Mouse and Touch.

Best regards
Sneeze
 
Can you share a minimal example of the problem you are seeing?

This seems to work for me regardless of mouse or screen touch:
MainWindow.xaml:
<Window x:Class="TestWpf.MainWindow"
        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:TestWpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Command="{Binding PressMeCommand}" Height="100" Width="100">Press Me</Button>
    </Grid>
</Window>

MainWindow.xaml.cs:
using System.Windows;
using System.Windows.Input;

namespace TestWpf
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            DataContext = new MainWindowViewModel();
            InitializeComponent();
        }
    }

    public class MainWindowViewModel
    {
        public ICommand PressMeCommand { get; init; } = new PressMeCommand();
    }

    public class PressMeCommand : ICommand
    {
        public event EventHandler? CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public bool CanExecute(object? parameter)
            => true;

        public void Execute(object? parameter)
            => MessageBox.Show("Pressed");
    }
}
 
Back
Top Bottom