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 ...

Get Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.