none
Some times PreviewMouseLeftButtonDown event get fired twice when using touch RRS feed

  • Question

  • Hello,

    I am using Windows 10 OS and my WPF application should support touchscreen. My WPF application has complex UI view.

    I have implemented PreviewMouseLeftButtonDown event to handle both mouse and touch event. When I use touch some times (randomly. NOT always) this event get fired twice. Using mouse, it always works fine. So I created very simple application having canvas with this event.

    In this application also, sometime (Mostly first time. Please run code multiple time to reproduce the issue as it happens randomly) this event get fired twice. Please have a look into below sample application code.

    Kindly help me to resolve this issue.

    View.xaml

    <Window x:Class="TouchScreen.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:infControls="clr-namespace:TouchScreen"
            xmlns:local="clr-namespace:TouchScreen"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
        
            <Canvas
                Width="900" Height="900"
                Background="Yellow"
                PreviewMouseLeftButtonDown="Canvas_PreviewMouseLeftButtonDown">
                
            </Canvas>
    </Window>

    View.xaml.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.Navigation;
    using System.Windows.Shapes;

    namespace TouchScreen
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
            private int count = 0;
            private void Canvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                Console.WriteLine("Mouse clicked " + count++);
            }
        }
    }

    Friday, January 4, 2019 4:53 AM

All replies