I have managed to acquire a preproduction version of the new Windows phone manufactured by LG, and have been given permission to write about it (most of it, anyway). In coming weeks, I’ll be blogging about the phone and providing key insights for developers looking to build apps for it with Silverlight.

I’ll start with something simple: the Back button. Every Windows phone has a Back button that functions like a browser’s Back button. I like this, because on the iPhone, I often have to go all the way back to the main screen just to back out of what I’m currently doing.

The Back button is accompanied by a Start button and a Search button, and Windows phones have other buttons as well: for example, a power button and a camera-shutter button. But the Back button is the only one that you can hook in software. When pressed, the Back button fires a BackKeyPress event. The UI Design and Interaction Guide for Windows Phone 7 says this about handling BackKeyPress events:

Developers should only implement Back Button behaviors that navigate back or dismiss context menus or modal dialog boxes. All other implementations are prohibited.

This warning is more than a formality. If an app contravenes this directive, Microsoft won’t allow it to be published in the Marketplace.

For the most part, developers won’t need to hook BackKeyPress events because the Back button works without any program intervention. However, one practical use for BackKeyPress events is to prompt the user to save data before navigating away from your app, or to let the user cancel a Back-button navigation event. Here’s a simple example that hooks the Back button and asks the user to confirm that they want to navigate away:

this.BackKeyPress +=

    new EventHandler<System.ComponentModel.CancelEventArgs>(OnBackKeyPress);

      .

      .

      .

void OnBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)

{

    MessageBoxResult result = MessageBox.Show("Are you sure?", "Confirm",

        MessageBoxButton.OKCancel);

    e.Cancel = !(result == MessageBoxResult.OK);

}

Here’s how it looks in the Windows phone emulator:

BackKeyPress 

In discussions with Microsoft personnel, it was agreed that this is a legitimate use of BackKeyPress events and that it would not prevent an app from being published in the Marketplace.