Vibrating the phone

Windows Phone Tutorial

A little vibration added to your application can be just the haptic feedback needed. It turns out that vibration is absurdly easy to add; so much so that discussions of adding vibration typically come with the caveat that you want to use it sparingly; too much of a good thing can make for a very annoying application.

To see how to add vibration to an application, let’s start by creating a new application named Vibrate. 

The UI is dead simple, just a button centered on MainPage.xaml,

<Button
   Content="Vibrate"
   Name="Vibrate" 
   Height="100"
   Width="300"/>

The event handler for this button will call the Vibrate Controller’s Start method passing in a value for how long to vibrate.  You’ll need to add a using statement for Microsoft.Devices.

 void Vibrate_Click( 
     object sender, 
     RoutedEventArgs e )
 {
     VibrateController.Default.Start( 
         TimeSpan.FromMilliseconds( 200 ) );
 }

That’s really all there is to it.  Press the button, the phone vibrates.  You can imagine using this in a game of course, but also for specific (and startling) feedback in other applications as well.

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in Essentials, Mango, Mini-Tutorial, WindowsPhone and tagged . Bookmark the permalink.

3 Responses to Vibrating the phone

  1. Loreen's avatar Loreen says:

    Heya terrific website! Does running a blog simikar to this require a large
    amount of work? I’ve absolutely no understanding of computer programming howeve I was hoping to start my own blog in the
    near future. Anyhow, should yyou have aany suggestions or tips for new blog owners please
    share. I understand this is off subject however I simply
    had to ask. Thaanks a lot!

  2. I constantly spent my half an hour to read this blog’s content every day along with a cup of coffee.

  3. Sanjeev Ahuja's avatar Sanjeev Ahuja says:

    Hi!
    I am developing an app where I need to change the vibrating frequency of the windows phone . The normal phone vibrates at 120-150 hz , I would like to change it to 128 hz precisely . Please help .

Comments are closed.