使用touchDown模拟Datagrid中的双击事件

son*_*iya 5 c# wpf mouse datagridview emulation

我是WPF的新手.我有一个带有数据网格的WPF窗口,它会在双击时启动进程.这项工作很棒,但是当我在平板电脑(使用Windows 7)中使用触摸屏时,这个过程永远不会发生.所以我需要使用触摸事件模拟双击事件.有人可以帮我这么做吗?

Lia*_*roy 0

请参阅如何在 C# 中模拟鼠标点击?了解如何模拟鼠标单击(在 Windows 窗体中),但它在 WPF 中可以通过执行以下操作来工作:

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's 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);
    }
}
}
Run Code Online (Sandbox Code Playgroud)