O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the Motion Sensor

The sample code for this section follows the same pattern as the code for the gyroscope. The viewmodel’s Start method first tests whether the motion sensor is supported, and then creates a new Motion instance, subscribes to its CurrentValueChangedEvent, and calls its Start method. See the following excerpt:

public void Start(){    if (!Motion.IsSupported)    {        MessageService.ShowMessage(            "Motion is not supported on this device.");        return;    }    motion = new Motion();    double interval = motion.TimeBetweenUpdates.TotalMilliseconds;    motion.CurrentValueChanged += HandleMotionCurrentValueChanged;    motion.Start();}

The Motion sensor’s TimeBetweenUpdates property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required