Shake Gestures Windows Phone

357 views Asked by At

I am using a Shake Gestures method which was claimed to work; however it isn't on my end. Note that this method is based on the sample provided by Microsoft. The steps I followed are the following. Please can anyone help me out?

Step 1: Add reference to shake gestures library, ShakeGestures.dll

Step 2: Add a using statement to file header

using ShakeGestures;

Step 3: Register to ShakeGesture event in your intialize or activate method

 public MainPage()
    {
        InitializeComponent();

        ShakeGesturesHelper.Instance.ShakeGesture += new
       EventHandler<ShakeGestureEventArgs>(Instance_ShakeGesture);

        // optional, set parameters
        ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 2;

        // start shake detection
        ShakeGesturesHelper.Instance.Active = true;
    }

Step 4: implement the ShakeGesture event handler from step 3

private void Instance_ShakeGesture(object sender, ShakeGestureEventArgse)
{

 Storyboard1.Begin();

}

The End. Thanks

1

There are 1 answers

0
Anmol Kumar On BEST ANSWER

Try this in the code-behind, worked for me.

using ShakeGestures;  //Add the reference

public MainPage()
{
 InitializeComponent();

 ShakeGesturesHelper.Instance.ShakeGesture += Instance_ShakeGesture; 
 ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 10;
 ShakeGesturesHelper.Instance.Active = true;
}

void Instance_ShakeGesture(object sender, ShakeGestureEventArgs e)
{
 Deployment.Current.Dispatcher.BeginInvoke(() =>
 {

  //Perform the required tasks.
 });


}