Double-click event emulation in Datagrid with touchDown

I am new to WPF. I have a WPF window with a datagrid in which the process starts when double-clicked. This works fine, but when I do this on a tablet (with windows 7) using the touch screen, the process will never happen. So I need to emulate a double click event with touch events. Can anyone help me do this please?

+5
source share
2 answers

See How to simulate a mouse click in C #? for how to emulate a mouse click (in the form of windows), but it works in WPF by doing:

using System.Runtime.InteropServices;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

    private const int MOUSEEVENTF_LEFTDOWN = 0x02;
    private const int MOUSEEVENTF_LEFTUP = 0x04;
    private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const int MOUSEEVENTF_RIGHTUP = 0x10;

    public void DoMouseClick()
    {
         //Call the imported function with the cursor current position
        int X = //however you get the touch coordinates;
        int Y = //however you get the touch coordinates;
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
    }
}
}
0
source

First add the mouse click function:

/// <summary>
/// Returns mouse click.
/// </summary>
/// <returns>mouseeEvent</returns>
public static MouseButtonEventArgs MouseClickEvent()
{
    MouseDevice md = InputManager.Current.PrimaryMouseDevice;
    MouseButtonEventArgs mouseEvent = new MouseButtonEventArgs(md, 0, MouseButton.Left);
    return mouseEvent;
}

click WPF:

private void btnDoSomeThing_Click(object sender, RoutedEventArgs e)
{
    // Do something
}

, click :

btnDoSomeThing_Click(new object(), MouseClickEvent());

, , PreviewMouseDoubleClick, , :

private void lvFiles_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    DoMouseDoubleClick(e);
}

private void DoMouseDoubleClick(RoutedEventArgs e)
{
    // Add your logic here
}

, (, KeyDown):

private void someControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
    if (e.Key == Key.Enter)
        DoMouseDoubleClick(e);
}
0

All Articles