locked
Why there is no DoubleTapped event in GestureRecognizer

    Question

  • I want to add double-tap to zoom feature to our application. I've told the gesture recognizer to recognize the double tap gesture along with other gestures with the code

        m_gestureRecognizer = ref new GestureRecognizer;
    
        // specify which gestures the application supports
        m_gestureRecognizer->GestureSettings = 
            GestureSettings::DoubleTap                    | // normal zoom
            GestureSettings::ManipulationScale            | // smooth zoom
            GestureSettings::ManipulationTranslateX       | // pan
            GestureSettings::ManipulationTranslateY       |
            GestureSettings::ManipulationTranslateInertia |
            GestureSettings::RightTap; // bring up context controls
    

    When I register gesture event handlers, I am surprised to find that there is DoubleTapped event in GestureRecognizer. So what can I do to handle double-tap gesture? Thanks.

    Thursday, August 09, 2012 4:35 PM

Answers

  • void TouchME::OnTapped(_In_ GestureRecognizer^ sender, _In_ TappedEventArgs^ args)
    {
        if (args->TapCount == 2 ) { // issue: the condition is always true
            OutputDebugString(L"DoubleTap gesture detected\n"));
        }
    }

    • Marked as answer by Leonard Tuesday, August 14, 2012 10:43 PM
    Tuesday, August 14, 2012 8:57 PM
    Owner

All replies

  • Check CanBeDoubleTap in your Tapped event handler.

    --Rob

    Friday, August 10, 2012 7:34 AM
    Owner
  • Thanks Rob. But the CanBeDoubleTap method always returns true for both single tap and double tap. This method requires a PointerPoint parameter. As I cannot get this parameter from the input parameters of the Tapped event handler, I obtain it from the OnPointerPress event handler. Here is my code:

    // header file
    ref class TouchME : public Windows::ApplicationModel::Core::IFrameworkView
    {
    ......
        Windows::UI::Input::GestureRecognizer^ m_gestureRecognizer; 
        Windows::UI::Input::PointerPoint^ m_pointerPoint;
    };
    
    // implementation file
    void TouchME::OnPointerPressed(_In_ CoreWindow^, _In_ PointerEventArgs^ args)
    {
        unsigned int pointerId = args->CurrentPoint->PointerId;
        m_pointerPoint = PointerPoint::GetCurrentPoint(pointerId);
        m_gestureRecognizer->ProcessDownEvent(m_pointerPoint);
    }
    
    void TouchME::initGestureRecognizer()
    {
        m_gestureRecognizer = ref new GestureRecognizer;
        m_pointerPoint = nullptr;
    
        // specify which gestures the application supports
        m_gestureRecognizer->GestureSettings = 
            GestureSettings::Tap                          | // normal zoom
            GestureSettings::DoubleTap                    | 
            GestureSettings::ManipulationScale            | // smooth zoom
            GestureSettings::ManipulationTranslateX       | // pan
            GestureSettings::ManipulationTranslateY       |
            GestureSettings::ManipulationTranslateInertia |
            GestureSettings::RightTap; // bring up thumbnails and context controls
    
        // Register all the gesture event handlers
        _tokenTapped = m_gestureRecognizer->Tapped::add(
            ref new TypedEventHandler<GestureRecognizer^, TappedEventArgs^>(
                    this, &TouchME::OnTapped));
    ......
    }
    
    void TouchME::OnTapped(_In_ GestureRecognizer^ sender, _In_ TappedEventArgs^ args)
    {
        if ( m_gestureRecognizer->CanBeDoubleTap(m_pointerPoint) ) {
            OutputDebugString(TEXT("DoubleTap gesture detected\n"));
        }
    }
    
    I couldn't find the cause that makes CanBeDoubleTap return incorrect result. Please give me some help, thanks.
    Friday, August 10, 2012 10:34 AM
  • I want to add double-tap to zoom feature to my app. I use CanBeDoubleTap inside the OnTapped event handler to detect double-tap as suggested in the post (http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/fe938ad4-373a-4cdb-876e-c06180c65756). However, this method always returns true for both single and double tap. I notice this method requires a PointerPoint parameter. As I cannot get this parameter from the input parameters of the OnTapped event handler, I obtain it from the OnPointerPress event handler. Here is my code:

    // header file
    ref class TouchME : public Windows::ApplicationModel::Core::IFrameworkView
    {
    ......
        Windows::UI::Input::GestureRecognizer^ m_gestureRecognizer; 
        Windows::UI::Input::PointerPoint^ m_pointerPoint;
    };
    
    // implementation file
    void TouchME::OnPointerPressed(_In_ CoreWindow^, _In_ PointerEventArgs^ args)
    {
        unsigned int pointerId = args->CurrentPoint->PointerId;
        m_pointerPoint = PointerPoint::GetCurrentPoint(pointerId);
        m_gestureRecognizer->ProcessDownEvent(m_pointerPoint);
    }
    
    void TouchME::initGestureRecognizer()
    {
        m_gestureRecognizer = ref new GestureRecognizer;
        m_pointerPoint = nullptr;
    
        // specify which gestures the application supports
        m_gestureRecognizer->GestureSettings = 
            GestureSettings::Tap                          | // normal zoom
            GestureSettings::DoubleTap                    | 
            GestureSettings::ManipulationScale            | // smooth zoom
            GestureSettings::ManipulationTranslateX       | // pan
            GestureSettings::ManipulationTranslateY       |
            GestureSettings::ManipulationTranslateInertia |
            GestureSettings::RightTap; // bring up thumbnails and context controls
    
        // Register all the gesture event handlers
        _tokenTapped = m_gestureRecognizer->Tapped::add(
            ref new TypedEventHandler<GestureRecognizer^, TappedEventArgs^>(
                    this, &TouchME::OnTapped));
    ......
    }
    
    void TouchME::OnTapped(_In_ GestureRecognizer^ sender, _In_ TappedEventArgs^ args)
    {
        if ( m_gestureRecognizer->CanBeDoubleTap(m_pointerPoint) ) { // issue: the condition is always true
            OutputDebugString(TEXT("DoubleTap gesture detected\n"));
        }
    }

    Tuesday, August 14, 2012 2:50 PM
  • void TouchME::OnTapped(_In_ GestureRecognizer^ sender, _In_ TappedEventArgs^ args)
    {
        if (args->TapCount == 2 ) { // issue: the condition is always true
            OutputDebugString(L"DoubleTap gesture detected\n"));
        }
    }

    • Marked as answer by Leonard Tuesday, August 14, 2012 10:43 PM
    Tuesday, August 14, 2012 8:57 PM
    Owner
  • Thank you. It works.
    Tuesday, August 14, 2012 10:43 PM