O'Reilly logo

Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® by Robert Fonseca-Ensor, Karli Watson, Nick Lecrenski

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

CHAPTER 6 EXERCISE SOLUTIONS

Exercise 1 Solution

The Windows Phone 7 hardware specification says that the accelerometer and compass are mandatory. Vibration is optional, and at the time of writing, there are no plans to include thermometer or altimeter sensors. It would probably be possible to get both of these environmental values through online services that could provide this information based on location information.

Exercise 2 Solution

You can restrict a page to portrait orientation only by setting the PhoneApplicationPage.SupportedOrientations property as follows:

<phone:PhoneApplicationPage… SupportedOrientations=“Portrait”… >

Exercise 3 Solution

You can disable the Back button by canceling every event received. For example, you can do this with the following code:

private void MainPage_BackKeyPress(
   object sender, System.ComponentModel.CancelEventArgs e)
{
   e.Cancel = true;
}

However, you should avoid doing this because it prevents users from exiting the page by using the Back button. Remember that you should ensure that the button still functions as users expect it to.

Exercise 4 Solution

You can tell whether the accelerometer sensor is disabled in a device by looking at its State property. The value SensorState.Disabled indicates that it is disabled. Other sensors may also expose a property of this type.

Exercise 5 Solution

You can modify the generateReadingsWorker_DoWork() method of the AccelerometerSensorWrapper class as follows:

public void generateReadingsWorker_DoWork(object ...

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