开发者

Cancel touches events on Windows Phone

开发者 https://www.devze.com 2023-02-03 09:29 出处:网络
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 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 :

       开发者_Python百科                     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);


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");
}


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(...));
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消