Programming Windows Phone 7 LOB Applications – Part I

July 22, 2010

no comments


In these post series, I’ll demonstrate how to develop LOB applications for the Windows Phone 7. This series will provide an easy start for iPhone, Android and .NET Programmers.


Windows Phone is almost here, and it’s a great timing to learn how to develop applications which target the Windows Phone 7 device.

From my point of view, there are at least three reasons for doing so:

1. Microsoft introduces a market place, so it’s a good opportunity for making easy money 🙂

2. Develop LOB Applications for Windows Phone, which is part of my job.

3. Just for Fun!

Where to Start

If you’re a .NET Programmer, you’ve already made half of the way. All you have to do is to learn Silverlight and/or XNA for gaming.

If you’re an iPhone programmer and you know Cocoa Touch and Objective C, you’ve to learn: Silverlight, C# and/or XNA for gaming.

If you’re an Android programmer and you know Java or C++, you’ve to learn: Silverlight, C# and/or XNA for gaming.

Whatever kind of programmer you’re, both C# and Silverlight are easy to learn. Just for clarification, C# is a programming language (comparing to Objective C, C++ and Java), where Silverlight is the framework for developing UI and client logic (comparing to Cocoa Touch and Java).

Windows Phone SDK

Before we start, we have to install the free Windows Phone Developer Tools Beta from here.

The Windows Phone Developer Tools Beta includes the following
– Visual Studio 2010 Express for Windows Phone Beta (Development Environment such as Xcode and Eclipse)
– Windows Phone Emulator Beta (Emulator if you don’t have a real device)
– Silverlight for Windows Phone Beta (UI and client logic framework)
– Microsoft Expression Blend for Windows Phone Beta (Great UI design environment)
– XNA Game Studio 4.0 Beta (Platform for game programming)

Note that Visual Studio 2010 Express won’t be installed if you already have Visual Studio 2010.

Windows Phone SDK

After installing the development environment, you can easily create a new Windows Phone project from both Visual Studio and Blend for Windows Phone. So feel free to launch Visual Studio or Blend for Windows Phone from the start menu, then click File –> New Project.

image image

Both Visual Studio and Blend offer three kind of project templates. For the simplicity I’ve chosen the “Windows Phone Application” project template.

Now let’s look at the results. In both Visual Studio and Blend we can find two .xaml files, two .png files and one .jpg file.

The image files are application icon, background and splash screen. Feel free to change them to whatever you like. But just for the beginning, keep the files name and type.

The App.xaml file is a special XML file, represents part of the application class. If you expand it, you’ll see another App.xaml.cs file which is another part of the same application class written in C#. The App.xaml is usually used to add UI resources. Let’s look at the content inside.

imageAs you can see, this XAML file defines the App class located inside FirstApp namespace (like package in Java, but logically).

An interesting part of this XAML file defines a PhoneApplicationService which provides access to various aspects of the application’s lifetime. This includes management of the application’s idle behavior and management of the application’s state when it becomes active or inactive. For example When UserIdleDetectionMode is set to enabled, the operating system will consider an application to be idle when no touch events are detected. When ApplicationIdleDetectionMode is set to enabled, the operating system will pause the active application when the lock screen is engaged.

Looking at the App.xaml.cs file we can find the second part of the App class (there is a third part which is automatically generated by a build tool).


In this part of the App class you can find an empty implementation of all the PhoneApplicationService event handlers (registered from XAML: Launching, Closing, Activated, Deactivated). These event handlers are left empty so you can place your relevant code over there.

Other parts of the implementation are:

* Unhandled exception handling – If Visual Studio debugger is attached to the running application (for example, hitting F5 to run this application) it will break whenever an unhandled exception is cough.

* InitializeComponent – calling this method, loads the BAML (XAML “compiled” content) from the assembly resources.

* InitializePhoneApplication – This method contains the following code:


The main part of the code above is creating a PhoneApplicationFrame which hosts the MainPage.xaml. Setting PhoneApplicationFrame as the root-frame doesn’t renders it until placing it as the root-visual element. This allows the splash screen to remain active until the application is ready to render.

Designing the Main Page

Now let’s look at the MainPage.xaml. Opening it with Blend or the Visual Studio 2010 WP7 Designer, you can see how the main page looks like and design it as well.

image image

Let’s change the “MY APPLICATION” title to “My First WP7 App”, and “page name” to “Hello World!”. To do that, select the “MY APPLICATION” text-block and change its Text property. Repeat these steps for the second text-block.


Now let’s add a several images to this page. To do that, go to the Projects tab in blend, and add an existing image to the project. Now just drag the image file you’ve added to the page. Blend will create an Image object automatically.


Testing the Application

Since currently I don’t have a Windows Phone device, I’ll use the WP7 emulator which arrives with the WP7 SDK.

Hitting F5 from both Visual Studio and Blend will automatically launch the WP7 emulator, then the application we’ve just created.


To exit or stop debugging, you may click the back button, click on the home button or stop the debugging session from Visual Studio. Don’t exit the emulator, just leave it open for next use.

Enjoy your Windows Phone 7 Programming and stay tuned for more.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>