|
In this article I will talk about Touchpanel GestureSample implementation in Windows Phone which is available in Microsoft.Xna.Framework.Input.Touch assembly.
There are 11 GestureType listed below.
1. GestureType.Hold 2. GestureType.Tap 3. GestureType.DoubleTap 4. GestureType.Flick 5. GestureType.Pinch 6. GestureType.DragComplete 7. GestureType.FreeDrag 8. GestureType.HorizontalDrag 9. GestureType.VerticalDrag 10. GestureType.PinchComplete 11. GestureType.None
Let's write code to implement this.
Step 1: Add a textblock and rectangle in MainPagel.xaml
<TextBlock Height="104" HorizontalAlignment="Left" Margin="100,500,0,0" FontSize="50" Foreground="YellowGreen" TextAlignment="Center" Name="testGesture" Text="Test Gesture" VerticalAlignment="Top"/>
<Rectangle Fill="Orange" Height="400" Width="400" x:Name="rect"> </Rectangle>
Step 2: Place below code in the contructor of MainPage.xaml.cs which will enable the gestures for touchpanel on rectangle.
TouchPanel.EnabledGestures = GestureType.Hold | GestureType.Tap | GestureType.DoubleTap | GestureType.Flick | GestureType.Pinch | GestureType.DragComplete | GestureType.FreeDrag | GestureType.HorizontalDrag | GestureType.VerticalDrag | GestureType.PinchComplete;
Step 3: Place below code also in the constructor of MainPage.Xaml.cs which will add ManipulationCompleted event handler to rectangle.
rect.ManipulationCompleted += new EventHandler<ManipulationCompletedEventArgs>(rect_ManipulationCompleted);
One can boud ManipulationCompleted event to LayoutRoot as well.
Step 4: Now add below code in the MainPage.Xaml.cs, below the constructor.
void rect_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) { while (TouchPanel.IsGestureAvailable) { GestureSample gestureSample = TouchPanel.ReadGesture(); switch (gestureSample.GestureType) { //case GestureType.DragComplete: // testGesture.Text = "DragComplete"; // break; //case GestureType.PinchComplete: // testGesture.Text = "PinchComplete"; // break;
case GestureType.FreeDrag: testGesture.Text = "FreeDrag"; break; case GestureType.HorizontalDrag: testGesture.Text = "HorizontalDrag"; break; case GestureType.Pinch: testGesture.Text = "Pinch"; break;
case GestureType.VerticalDrag: testGesture.Text = "VerticalDrag"; break;
case GestureType.Tap: testGesture.Text = "Tap"; break;
case GestureType.DoubleTap: testGesture.Text = "Double Tap"; break;
case GestureType.Hold: testGesture.Text = "Hold"; break;
case GestureType.Flick: testGesture.Text = "Flick"; break; } } }
Step 5: Now run the application and test different gestures on the screen of Windows Phone.

This ends the article of Windows Phone Gestures.
|