Chapter 10. Shake, Rattle, and Vibrate


  • Understanding how to interact with the accelerometer

  • How to simulate the accelerometer in the Windows Phone emulator

  • How to use a Wii remote to test applications that use the accelerometer

  • How to vibrate the Windows Phone

I wouldn't recommend that you dunk your Windows Phone in a martini, but your application can definitely let you know if it's being shaken or stirred. All Windows Phone devices will have an integrated accelerometer that you can use to track the motion of the device.

In this chapter you will see how to register for events that fire whenever the direction and physical orientation of the device change. You will also learn how you can cause the device to vibrate in order to provide tactile feedback to the user.


Applications designed for Windows Phone can accept input from the user in various ways. Traditional desktop applications may accept input from the keyboard, mouse, and, more recently, a touch screen. On a mobile device, the user is no longer desk-bound, and thus there are other input devices that can be used to interact with the application's user interface (UI). The accelerometer is one such input sensor — it detects the acceleration of the device as the user moves or rotates it.

The Windows Phone accelerometer reports a three-dimensional (3D) vector, in the form of individual x, y, and z values. These values indicate the direction and magnitude of the force currently applied to the device.

Get Professional Windows® Phone 7 Application Development: Building Applications and Games Using Visual Studio, Silverlight®, and XNA® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.