using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using Microsoft.Phone.Controls;
namespace WindowsPhoneGestureListenerDemo
{
public partial class MainPage : PhoneApplicationPage
{
Random rand = new Random();
// Constructor
public MainPage()
{
InitializeComponent();
}
private void GestureListener_Tap( object sender, GestureEventArgs e)
{
if (e.OriginalSource == rectangle)
{
rectangle.Fill = new SolidColorBrush(
Color.FromArgb( 255 , ( byte )rand.Next( 256 ),
( byte )rand.Next( 256 ),
( byte )rand.Next( 256 )));
}
var position = e.GetPosition(rectangle);
Debug.WriteLine( " Tap\n " );
}
private void GestureListener_DoubleTap( object sender, GestureEventArgs e)
{
translation.X = translation.Y = 0 ;
Debug.WriteLine( " DoubleTap\n " );
}
private void GestureListener_Flick( object sender, FlickGestureEventArgs e)
{
Debug.WriteLine( " Flick " );
Debug.WriteLine( " Angle: " + e.Angle);
Debug.WriteLine( " Direction: " + e.Direction.ToString());
Debug.WriteLine( " HorizontalVelocity(X): " + e.HorizontalVelocity.ToString() + " VerticalVelocity(Y): " + e.VerticalVelocity.ToString() + " \n " );
}
private void GestureListener_Hold( object sender, GestureEventArgs e)
{
Debug.WriteLine( " Hold\n " );
MessageBox.Show( " You are holding the rectangle! " , " Hold " , MessageBoxButton.OK);
}
private void GestureListener_GestureBegin( object sender, GestureEventArgs e)
{
var position = e.GetPosition(rectangle);
Debug.WriteLine( " GestureBegin " );
Debug.WriteLine( " GestureBegin Point: X: " + position.X + " Y: " + position.Y + " \n " );
}
private void GestureListener_GestureCompleted( object sender, GestureEventArgs e)
{
var position = e.GetPosition(rectangle);
Debug.WriteLine( " GestureCompleted " );
Debug.WriteLine( " GestureCompleted Point: X: " + position.X + " Y: " + position.Y + " \n " );
}
private void GestureListener_DragStarted( object sender, DragStartedGestureEventArgs e)
{
Debug.WriteLine( " DragStarted " );
Debug.WriteLine( " Direction: " + e.Direction.ToString() + " \n " );
}
private void GestureListener_DragDelta( object sender, DragDeltaGestureEventArgs e)
{
this .translation.X += e.HorizontalChange;
this .translation.Y += e.VerticalChange;
Debug.WriteLine( " DragDelta " );
Debug.WriteLine( " Direction: " + e.Direction.ToString());
Debug.WriteLine( " Change: " + " X: " + e.HorizontalChange.ToString() + " Y: " + e.VerticalChange + " \n " );
}
private void GestureListener_DragCompleted( object sender, DragCompletedGestureEventArgs e)
{
Debug.WriteLine( " DragCompleted " );
Debug.WriteLine( " Direction: " + e.Direction.ToString());
Debug.WriteLine( " HorizontalChange(X): " + e.HorizontalChange.ToString() + " VerticalChange(Y): " + e.VerticalChange);
Debug.WriteLine( " HorizontalVelocity(X): " + e.HorizontalVelocity.ToString() + " VerticalVelocity(Y): " + e.VerticalVelocity.ToString() + " \n " );
}
}
}