Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get swipe in windows phone 7

I want to swipe images in windows phone 7. Where do I begin from?

like image 237
Shaireen Avatar asked Dec 03 '10 03:12

Shaireen


3 Answers

You can use the GestureService in the Silverlight Control Toolkit for Windows Phone 7. In your UI element, add the following piece of code (after you have referenced the toolkit's DLL in your WP7 project) -

<toolkit:GestureService.GestureListener>
    <toolkit:GestureListener Flick="OnFlick"/>
</toolkit:GestureService.GestureListener>  

Implement the handler OnFlick in the code-behind file, like so -

private void OnFlick(object sender, FlickGestureEventArgs e)
{
   var vm = DataContext as SelectedCatalogViewModel;
   if (vm != null)
   {
      // User flicked towards left
      if (e.HorizontalVelocity < 0)
      {
         // Load the next image 
         LoadNextPage(null);
      }

      // User flicked towards right
      if (e.HorizontalVelocity > 0)
      {
         // Load the previous image
         LoadPreviousPage();
      }
   }
}

Hope this helps, indyfromoz

like image 51
indyfromoz Avatar answered Nov 20 '22 03:11

indyfromoz


If you don't want to use the silverlight toolkit you can use the XNA framework.

http://www.nickharris.net/2010/11/using-touchpanel-for-gestures-in-windows-phone-7/

like image 25
Phill Avatar answered Nov 20 '22 04:11

Phill


Try this:

using Microsoft.Phone.Controls;

public partial class MyControl
{
    public MyControl()
    {
        InitializeComponent();

        var gl = GestureService.GetGestureListener(asd);
        gl.Flick += new EventHandler<FlickGestureEventArgs>(GestureListener_Flick);
    }

    private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
    {
        if (e.Direction == Orientation.Horizontal)
        {
            if (e.HorizontalVelocity < 0) // determine direction (Right > 0)
            {
                //Some Action
            }
            else
            {
                //Some Action
            }
        }
    }
}
like image 25
Sorokin Andrey Avatar answered Nov 20 '22 03:11

Sorokin Andrey