How to make your Windows Phone Vibrate using C#

There are many reasons why you might want to programmatically vibrate the phone during apps or games.  You might want to alert the user to an error condition or you want the user to actually feel that he has touched/clicked a button on the Phone.

The Windows Phone 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;

private void button1_Click(object sender, RoutedEventArgs e)
   VibrateController vibrate = VibrateController.Default;

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

You can use the methods Start and Stop of VibrateController to switch on/off the Vibrate controller.


Comments (2)

  1. bella says:

    nice post

  2. carl says:

    It's nice! but how to vibrate phone in the background? just like the default alarms app.

    If you know it, please help me. my email is thanks!

Skip to main content