wp7appdevelopment

Adventures in Windows Phone app development

How to Make a Windows Phone 7 Vibrate (C#)

Vibrate your phone?

There are many reasons you might want to programmatically vibrate the phone during apps or games.  You might want to alert the user to an error condition, and emphasize that a button has been clicked.

The Windows Phone 7 SDK makes it easy for developers to control the vibrate function easily, using the VibrateController class. The VibrateController class is defined in the namespace Microsoft.Devices.

The following example shows how to vibrate the phone using C#:


using Microsoft.Devices;

VibrateController vibrate = VibrateController.Default;
vibrate.Start(TimeSpan.FromMilliseconds(200));

That’s all that you need to do! You can change the vibrate duration — this example uses 200 milliseconds.
Of course, common-sense best practices: don’t overdo the use of vibration, and give the user the option to disable.

References

VibrateController class documentation

Leave a comment