locked
Failed to start tracking the pointer, because it is already being tracked.

    Question

  • I am trying to do "swipe select" on a GridViewItem to call a function for changing the appbar related to the context.

    I tried adding

    PointerPressed="GridView_PointerPressed_2" PointerMoved="GridView_PointerMoved_1" PointerReleased="GridView_PointerReleased_1"

    to the GridViewITem's data template (to <Canvas> the outer element),

    to the GridView itself,

    to the ScrollViewer containing all (currently i've removed ScrollViewer to see anything changes, but nothing is changed)

    in none of the above situations (seperately), i couldn't succeed in getting a successfull PointerReleased which i think is the reason for the Exception my application is throwing: "Failed to start tracking the pointer, because it is already being tracked." I think it is because pressDowns are not balanced with the pressUps.. Am I wrong?

    What am i missing here?

    By the way, codes for these functions:

           private void GridView_PointerPressed_2(object sender, PointerRoutedEventArgs e)
           {
               gr.ProcessDownEvent(e.GetCurrentPoint(pageRoot));
           }
    
           private void GridView_PointerMoved_1(object sender, PointerRoutedEventArgs e)
           {
               gr.ProcessMoveEvents(e.GetIntermediatePoints(pageRoot));
           }
    
           private void GridView_PointerReleased_1(object sender, PointerRoutedEventArgs e)
           {
               gr.ProcessUpEvent(e.GetCurrentPoint(pageRoot));
           }

    AND

    gr = new GestureRecognizer();
                 gr.GestureSettings = GestureSettings.CrossSlide;
                 gr.CrossSliding += new TypedEventHandler<GestureRecognizer, CrossSlidingEventArgs>(gr_CrossSliding);

    • Edited by ELRaymod Saturday, June 9, 2012 5:22 AM
    Saturday, June 9, 2012 5:21 AM

Answers

  • Hello,

    I've been talking to our Product Group. They told me that the issue you're describing (PointerRelease doesn't get called) is actually by design. 

    The PointerPress event firing does not have a 1:1 guarantee with PointerRelease event. In the case of your repro app, the GridView is contained within a ScrollViewer. What's happening is that when you do the "swipe" gesture, you've moved your pointer by > 2.7 mm, which results in DirectManipulation (in the ScrollViewer) taking over. If you call Capture() on the pointer in your pressed event, you will be called back with a PointerCaptureLost event when DM takes over. Once DM takes over, you will not receive any more Pointer* events as it is now swalling all pointer messages until the finger is lifted and inertia (if any) is allowed to dissipate.

    Basically, once DM has taken over there's no more Pointer events, and this is by design.


    --------------------------------------------------------------------------------

    Alejandro Campos Magencio - Microsoft Escalation Engineer - Forum Moderator
     If my reply answers your question, please mark this post as answered.

    Thursday, June 21, 2012 12:27 PM
    Moderator

All replies

  • Checking this out.


    --------------------------------------------------------------------------------

    Alejandro Campos Magencio - Microsoft Escalation Engineer - Forum Moderator
     If my reply answers your question, please mark this post as answered.

    Friday, June 15, 2012 8:47 AM
    Moderator
  • I added your code to a GridView, and I always get a PointerReleased after a PointerPressed on Windows 8 RP.

    May you please share a repro project with me? If so, please send it to my email address alejacma at microsoft.com. Thank you.


    --------------------------------------------------------------------------------

    Alejandro Campos Magencio - Microsoft Escalation Engineer - Forum Moderator
     If my reply answers your question, please mark this post as answered.

    Friday, June 15, 2012 8:58 AM
    Moderator
  • Thank you, i've sent you a zip and a screenshot with subject: msdn forums - tracking failure
    Friday, June 15, 2012 9:32 AM
  • I was able to repro the issue with your sample. I’m working on it.

    --------------------------------------------------------------------------------

    Alejandro Campos Magencio - Microsoft Escalation Engineer - Forum Moderator
     If my reply answers your question, please mark this post as answered.

    Monday, June 18, 2012 10:28 AM
    Moderator
  • I'm creating a bug on this.

    --------------------------------------------------------------------------------

    Alejandro Campos Magencio - Microsoft Escalation Engineer - Forum Moderator
     If my reply answers your question, please mark this post as answered.

    Wednesday, June 20, 2012 11:31 AM
    Moderator
  • Thank you!
    Wednesday, June 20, 2012 11:38 AM
  • Hello,

    I've been talking to our Product Group. They told me that the issue you're describing (PointerRelease doesn't get called) is actually by design. 

    The PointerPress event firing does not have a 1:1 guarantee with PointerRelease event. In the case of your repro app, the GridView is contained within a ScrollViewer. What's happening is that when you do the "swipe" gesture, you've moved your pointer by > 2.7 mm, which results in DirectManipulation (in the ScrollViewer) taking over. If you call Capture() on the pointer in your pressed event, you will be called back with a PointerCaptureLost event when DM takes over. Once DM takes over, you will not receive any more Pointer* events as it is now swalling all pointer messages until the finger is lifted and inertia (if any) is allowed to dissipate.

    Basically, once DM has taken over there's no more Pointer events, and this is by design.


    --------------------------------------------------------------------------------

    Alejandro Campos Magencio - Microsoft Escalation Engineer - Forum Moderator
     If my reply answers your question, please mark this post as answered.

    Thursday, June 21, 2012 12:27 PM
    Moderator
  • Hello,

    Is there any sample around in which is explained how PointerCaptureLost is to be used with GestureRecognizer?

    The following exception: "Failed to start tracking the pointer, because it is already being tracked." is expected to be thrown by GestureRecognized even if PointerCaptureLost is used?

    Regards,

    Adrian

    Monday, July 16, 2012 8:01 PM
  • Any workaround for this yet?
    Monday, September 24, 2012 7:37 PM
  • I am also facing a similar problem. Can anyone please explain how to solve it?

    Wednesday, June 12, 2013 2:40 AM
  • Here is what I did to avoid this exception. I added a property telling if the pointer capture previously held is lost:

    /// <summary>
    /// Gets / sets a flag indication whether 
    /// the pointer capture previously held is lost.
    /// </summary>
    private bool PointerCaptureIsLost { get; set; }
    

    Also, a PointerCaptureLost event handler is added that sets the flag:

    /// <summary>
    /// Invoked when pointer capture previously held 
    /// by an element moves to another element or elsewhere.
    /// </summary>
    /// <param name="sender">Sender of the event.</param>
    /// <param name="args">Event arguments.</param>
    private void OnCoreWindowPointerCaptureLost
      (
      object sender,
      PointerEventArgs args
      )
    {
      // Just set the flag that we've lost the capture.
      PointerCaptureIsLost = true;
    }
    


    In the PointerPressed handler, before calling the GestureRecognizer, I check the flag. In case it is set, which means the pointer capture is lost, only the flag is reset.

    /// <summary>
    /// Invoked when the pointer device initiates a Press action.
    /// </summary>
    /// <param name="sender">Sender of the event.</param>
    /// <param name="args">Event arguments.</param>
    private void OnCoreWindowPointerPressed
      (
      object sender,
      PointerEventArgs args
      )
    {
      // In case we've lost the pointer capture, 
      // just reset the flag and do nothing.
      // Otherwise, an exception will be thrown that says 
      // "Failed to start tracking the pointer, because it is already being tracked".
      if (PointerCaptureIsLost)
      {
        PointerCaptureIsLost = false;
        return;
      }
    
      // We still have the capture, so handle the event.
      GestureRecognizer.ProcessDownEvent(args.CurrentPoint);
    }
    

    Hope this helps.

    Stefan

    Wednesday, August 7, 2013 4:46 PM