Handling 2, 3, 4, 5 Fingers Tapped, DoubleTap & Holding Gestures in WinRT App

荒凉一梦 提交于 2019-12-10 03:17:11

问题


I can easily handle 1 finger Tapped, DoubleTap and Holding gestures like this:

public MainPage()
{
    this.InitializeComponent();
    this.Tapped += mc_Tapped;
    this.DoubleTapped += mc_DoubleTapped;
    this.Holding += mc_Holding;
}
public void mc_Tapped(object sender, TappedRoutedEventArgs e)
{
    //Tap
}
public void mc_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
    //DoubleTap
}
public void mc_Holding(object sender, HoldingRoutedEventArgs e)
{
    //Hold
}

But the events don't have a property to get the number of fingers and they don't even get fired when more than 1 touch contact is present on the screen. I also want to handle 2, 3, 4, 5 fingers Tapped, DoubleTap and Holding gestures. Can anyone tell me how to do that?


回答1:


You'll have to work with the PointerRoutedEventArgs that are passed on Pointer events (ie. Pressed, entered, released and such) and do it the hard way

Each time pointer enters the control is assigned a unique pointer ID.I would create a Dictionary and add each pointer to that dictionary as it is pressed on the control (and obviously remove them when they exit). Then in your existing tapped, double tapped and such handlers just check how many pointers are in your dictionary and call the appropriate handlers



来源:https://stackoverflow.com/questions/13011920/handling-2-3-4-5-fingers-tapped-doubletap-holding-gestures-in-winrt-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!