1. Preparing Your Machine
Before you can start writing applications for the phone, you must install the Windows Phone Developer Tools. Go to https://dev.windowsphone.com/
to download the tools called Windows Phone SDK. This website is the
starting point for downloading the tools as well as accessing the forums
if you have further questions about creating applications.
To install the Windows Phone SDK you must meet the minimum system requirements shown in Table 1.
Table 1. Windows Phone Developer Tools Requirements
Once you meet the requirements, you can run the vm_web.exe file that
you downloaded from the website to install the Windows Phone SDK. The
SDK installer includes Microsoft Visual Studio 2012 Express for Windows
Phone, Microsoft Blend Express for Windows Phone (the Express version of
Microsoft Expression Blend), and the Software Development Kit (SDK).
Visual Studio Express is the coding environment for Windows Phone. Blend
Express is the design tool for phone applications. And the SDK is a set
of libraries for creating phone applications and an emulator for
creating applications without a device.
In addition, the Windows Phone SDK’s phone emulator has additional
requirements. This is because the Windows Phone SDK for Windows Phone 8
includes an all new emulator that is a Hyper-V image (instead of the old
virtual machine technology). This matters as the emulator has steeper
requirements than the SDK itself. These requirements are shown in Table 2:
Table 2. Windows Phone Developer Tools Requirements
Tip
The Windows Phone emulator does not work well
in a virtual machine (e.g., Virtual PC, VMware, etc.) and is not
officially supported. The emulator is a virtual machine of the phone, so
running a virtual machine in a virtual machine tends to cause problems,
especially slow performance.
Visual Studio is the primary tool for writing
the code for your phone applications. Although the Windows Phone SDK
installs a version of Visual Studio 2012 Express specifically for phone
development, if you already have Visual Studio 2012 installed on your
machine the phone tools will also be integrated into this version of
Visual Studio. The workflow for writing code in both versions of Visual
Studio is the same. Although both versions offer the same features for
developing applications for the phone, in my examples I will be using
Visual Studio Express Edition for Windows Phone. In addition, I will be
using Blend Express, not the full version of Blend (i.e., Expression
Blend).
2. Creating a New Project
To begin creating your first Windows Phone application you will want
to start in one of two tools: Visual Studio or Expression Blend. Visual
Studio is where most developers start their projects, so we will begin
there, but we will also discuss how you can use both applications for
different parts of the development process.
2.1 Visual Studio
When you install the Windows Phone SDK you get a
version of Visual Studio 2010 Express that is used to create Windows
Phone applications only. When you launch Visual Studio 2012 Express you
will see the main window of the application, as shown in Figure 1.
Figure 1. Microsoft Visual Studio 2012 Express for Windows Phone
Click the New Project link on the Start page and you will be prompted
to start a new project. Visual Studio 2012 Express only supports
creating applications for Window Phone. In the New Project dialog (see Figure 2)
you will notice that only Windows Phone and XNA projects are shown. For
our first project we will start with a new project using the “Windows
Phone App” template and name it “HelloWorldPhone”.
Figure 2 New Project dialog
When you click the OK button to create the project, Visual Studio
will prompt you with a dialog where you can pick what version of the
phone to target (version 7.1 or 8.0), as seen in Figure 3.
Figure 3. Picking the phone version to target
Once Visual Studio creates the new project, you can take a quick tour of the user interface (as shown in Figure 4).
By default, Visual Studio shows two main panes for creating your
application. The first pane (labeled #1 in the figure) is the main
editor surface for your application. In this pane, every edited file
will appear separated with tabs as shown. By default, the MainPage.xaml
file is shown when you create a new Windows Phone application; this is
the main design document for your new application. The second pane (#2
in the figure) is the Solution Explorer pane and it displays the
contents of the new project.
Figure 4. The Visual Studio user interface
Another common pane that you will use is the toolbar, and it is
collapsed when you first use Visual Studio. On the left side of the main
window you will see a Toolbox tab that you can click to display the
Toolbox, as shown in Figure 5.
Figure 5. Enabling the toolbar
You may also want to click the pin icon to keep the toolbar shown at all times (as highlighted in Figure 5).
Before we look at how to create the application into something that
is actually useful, let’s see the application working in the device. You
will notice that in the toolbar (not the Toolbox) of Visual Studio
there is a bar for debugging. On that toolbar is a drop-down box for
specifying what to do to debug your application. This drop down should
already display the words “Emulator WVGA 512MB” as that is the default
when the tools are installed (as shown in Figure 6).
Figure 6. Using the emulator
At this point, if you press the F5 key (or click the triangular play
button on the debugging toolbar), Visual Studio will build the
application and start the emulator with our new application, as shown in
Figure 7.
Figure 7. The emulator
This emulator will be the primary way you
will debug your applications while developing applications for Windows
Phone. Our application does not do anything, so you can go back to
Visual Studio and click the square stop button on the debugging toolbar
(or press Shift-F5) to end your debugging session. You should note that
the emulator does not shut down. It is meant to stay running between
debugging sessions.