Windows Phone Zone
Windows Phone Zone is brought to you in partnership with:
spacer spacer Sumit Dutta
  • Bio
  • @sumitdutta21

I am mastered in computer application (MCA)and working as Architect in one of the leading software services company in India. I have more than 7 years of experience in software development. Sumit is a DZone MVB and is not an employee of DZone and has posted 22 posts at DZone. You can read more from them at their website. View Full User Profile

Windows Phone: Shake (it)

07.19.2012
spacer Email
Views: 1051
  • Tweet
  • spacer
It's so easy to get up and running with your first Windows Phone app!  Just pick up the FREE toolkit from Microsoft, register at AppHub, and start checking out some fundamental tutorials.

Related MicroZone Resources

Visual Studio Express 2012 for Win 8 is FREE!

Windows Phone SDK 7.1 FREE Download

Insider Tips for Windows 8 Development

Early Access! Windows 8 SDK

Like this piece? Share it with your friends:

| More

In this article I will talk about Windows Phone Shake gesture. Microsoft provides Shake gesture library which is available in AppHub.


Let's see how we can do this:


Step 1: Download Shake gesture library from create.msdn.com/en-us/education/catalog/article/Recipe_Shake_Gesture_Library


Step 2: Unzip Shake gestures library.zip and navigate to debug folder of ShakeGestures.


spacer


Step 3: Create a silverlight for Windows Phone project.


Step 4: Add ShakeGestures dll to project.


spacer


Step 5: Add a textblock inside contentpanel of MainPage.xaml.

<TextBlock Text="" "60" HorizontalAlignment="Left" Margin="100,100,0,0" Name="txtShakeType" VerticalAlignment="Top" FontSize="40" />

Step 6: Add ShakeGestures directive.

using ShakeGestures;
Step 7: Modify constructor of MainPage.xaml.cs as below. MinimumRequiredMovesForShake is set to 2 which means the device have to be shaked twice (One in each direction) on same axis.

public MainPage()
{
   InitializeComponent();
   ShakeGesturesHelper.Instance.ShakeGesture += new EventHandler<ShakeGestureEventArgs>(Instance_ShakeGesture);
   ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 2;
   ShakeGesturesHelper.Instance.Active = true;
}

Step 8: Instance_ShakeGesture will be invoked on shake of device to update UI.

private void Instance_ShakeGesture(object sender, ShakeGestureEventArgs e)
{
   this.Dispatcher.BeginInvoke(() =>
   {
      txtShakeType.Text = String.Format("Shaked Axis = {0}", e.ShakeType);
   });
}

Step 9: Now run the application and shake the device on X, Y and Z axis. The device will show shake along different axis like below.


spacer

This ends the article of Shake in Windows Phone.

Published at DZone with permission of Sumit Dutta, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:
  • Windows Phone
The Windows Phone Microzone, which is supported by Microsoft, is your one-stop-shop for news, tutorials, perspectives, and research on the mobile platform that is making waves in smartphone ecosystem.
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.