Thomas Joulin
Thomas Joulin

Reputation: 6650

Cancel touches events on Windows Phone

I have a list on images in a Pivot control. If you touch an image, it navigates to another view. If if flick through a new pivot and touch the image meanwhile, it navigates.

I noticed the Facebook app or the native photo albums don't have this bug.

Any idea ?

edit: the code :

                            Image img = new Image();
                            Delay.LowProfileImageLoader.SetUriSource(img, new Uri(adViewModel.Photos[k].ThbUrl));
                            img.Width = 150;
                            img.Tag = k;
                            img.Height = 150;
                            img.MouseLeftButtonDown += new MouseButtonEventHandler(launch_Diapo);
                            Grid.SetRow(img, i);
                            Grid.SetColumn(img, j);

                            PhotosGrid.Children.Add(img);

Upvotes: 1

Views: 346

Answers (2)

Matt Lacey
Matt Lacey

Reputation: 65586

If you can show your code we can probably provide a more specific answer.

However:

I'm guessing you're using MouseButtonLeftDown or similar to detect the touching of the image. Rather than this, use the Tap gesture from the toolkit. This should prevent the issue you're having.

There is a possible alternative to disable the pivot gesture while you're touching the image, but depending on how you're using the image within the pivotItem this may end up preventing proper pivot navigation.

You can add the Tap event in code like this:

var gl = GestureService.GetGestureListener(img);

gl.Tap += new EventHandler<GestureEventArgs>(gl_Tap);

and the handler would be something like this. (but actually doing something useful-obviously.)

void gl_Tap(object sender, GestureEventArgs e)
{
    MessageBox.Show("tapped");
}

Upvotes: 2

Vaysage
Vaysage

Reputation: 1366

Even I had a similar problem . What i did is ,check for MouseButtonLeftDown position and MouseButtonLeftUp position .If they are Equal navigate else do nothing .I will paste the code below.

Point temp;

void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    temp = e.GetPosition(null);
}

void img_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    Point point = e.GetPosition(null);
    if (point == temp)
    {
       this.NavigationService.Navigate(new Uri(...));
    }
}

Upvotes: 0

Related Questions