(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .

Windows Phone 7 - Part #1: Getting Started

(11 votes)
Andrea Boschin
>
Andrea Boschin
Joined Nov 17, 2009
Articles:   91
Comments:   9
More Articles
6 comments   /   posted on Jan 19, 2011
Categories:   Windows Phone

Last November Microsoft released its brand new Windows Phone 7 operating system, and many of you may have already bought one of the many models it can be found on the market. If you are, like me, passionate of tech-toys, probably you have already started to play with it, downloading tons of applications from the marketplace and you have permeated your life with the beautiful features of this phone. Now, since if you are reading this pages probably you are also passionate about programming with Silverlight, it is the right moment to get deeply in touch with your phone discovering how you can write your own applications, test them on your device and finally publish them to the marketplace to possibly start earn some money, I'm pretty sure you will use to buy your next toy. 

Starting with this article we will follow a path to discover one by one all the aspects of this device. I know for sure you may have already read something on Internet but from here I will start from scratch trying to give a full and complete view about what this phone can do and about what you can do with this phone.

This is the planned Table of Contents for the whole series. If you recommend adding another topic to the TOC - please feel free to comment below the article.

Windows Phone 7 Part #1: Getting Started
Windows Phone 7 Part #2: Your first app
Windows Phone 7 Part #3: Understanding navigation
Windows Phone 7 Part #4: The application lifecycle
Windows Phone 7 Part #5: Panorama and Pivot controls
Windows Phone 7 Part #6: Advanced interaction
Windows Phone 7 Part #7: Understanding Push Notifications
Windows Phone 7 Part #8: Using Sensors
  

Knowing the Phone

So, the first thing you need to know about your phone, is the phone itself. When you bought the device, you probably have on your side right now, you may have noticed that all the models, also if they come from many different brands, are pretty similar. All have a big screen, three buttons on the bottom, a camera and if you go deep inside the technical sheet you also know that there may be some little differences in memory size or in camera resolution but the main specs are really equal. This come from the choice Microsoft made of giving a number of fixed technical specification a phone must match to being able to run the operating system. I know you are aware you have 1 GHz processor, a minimum of 8 gb memory, an 800x480 screen and a fixed number of buttons. These and other strong limits are very important when you have to develop with this phone, because you may be sure that it does not matter what is the device that will run your application, it will runs equally everywhere. Since Microsoft does not want to start to build hardware, trying to put some limit to the creativity of the manufacturers should avoid many of the problems of the previous Windows Mobile platform.

CaptureAt the basis of the Windows Phone 7 operating system there is a new edition of the .NET Compact Framework v3.7. Please close the browser windows you have already popped out to search for a redistributable download. This release is not public and, at now, it is only mounted on the Windows Phone 7 devices. And please keep track that, as a developer, you will not be able to use any API of the NETCF. As you can see in the following scheme the CLR take great part in the development of the platform but the developer tools does not have any connection with it. All the underlying ecosystem, the kernel, the sensors, the important integration to the cloud and much more, are completely insulated and wrapped by the CLR and on top of it there are three blocks that refer to HTML/Javascript, XNA and Silverlight. These are the sole "architectural handles" we can use to develop application for our phone. So, if you develop applications for the browser you will use Javascript and HTML and for gaming options you will rely on the XNA framework. But for the most part of the applications you will find that Silverlight is the sole and unique toolset available.

See the light, the silvery one...

After a great circle we are now in touch with what we would like to know. Silverlight on the Windows Phone 7 is the tool we need to develop applications. Particularly we have here the full version 3.0. It is important to know that wherever you will find an API that is in common with the desktop edition it should function exactly the same way. This does not means you have the entire Silverlight 3.0 on your Phone. There is a number of features that have been taken down for security reasons or for lack of support or signifiance.  One for all, if you explore the assemblies you will find a Socket class but it has been made private so you cannot use it directly. The same way there is a number of assemblies that have been added to support the phone-only features but we will see at them during the next parts of the series. Another thing to remember is that Silverlight on the phone is a native development environment and it doesn't have anything to do with the browser. If a page hosts a Silverlight application it can't be run into the phone's browser.

An application, to run on the phone must be developed with Visual Studio 2010, compiled to a XAP file and loaded into the phone using Visual Studio itself or the Marketplace. It may seem a straightforward path, but there is some subtle thing you need to know. First of all the development tools. As I've already said you need Visual Studio 2010. There is a free express version available or a set of tools you can add to the full version. It is the same setup you can download from here: https://www.microsoft.com/express/Phone/

Included in the toolset there is also a version of Blend 4.0 and a tool that can be used to unlock the phone. This leads to the problem of the installation of the applications. Normally it is not possible to install anything on the phone that do not comes from the Marketplace. The phone is a closed environment and a normal user must crawl the Marketplace from inside the phone and download the applications from it. Obviously, as a developer, you need to side load your XAPs but for doing this you need to activate a developer account on the http://create.msdn.com/ website. To open this account you have to pay an annual fee that enable you to unlock up to three devices and install up to 10 application on each one. The same account let you publish your applications and have the Marketplace deliver your XAPs to the other users phones. To be clear, you can start immediately to develop your applications, because the developer tools includes an useful emulator, but before you decide to publish your applications it is required to unlock your phone to try the application on a real device because it is impossible to completely test it on the emulator.

To have your development environment to connect successfully to the phone you need also to download and install the Zune 4.7 software. This software is required because it serves as a bridge between the phone and your pc. So when you are developing you must have the zune running. It is a good excuse, to have good music playing while you are writing code.

Unlock, deploy and run

CaptureOnce you have the entire toolset installed and your markeplace account created, you can try to unlock the phone. First of all connect the device to the PC using the USB cable. Then starts the Zune software if it does not run automatically. Then go to the settings page of the phone and change the option that automatically lock the screen of your phone after a while. I usually put this option to "never" while I'm developing because, to successfully deploy your apps, you need to have the phone unlocked. Remember to set the option again once you have finished a development session to avoid high battery comsumption.

Then you can open the unlock tool from the start menu (see the figure on the side), and enter the windows live id credentials you have used to register to the marketplace. Sometimes the tool fails the unlock process, perhaps due to communication issues, but in one or two attempts you will have your phone ready for your next application.

Now, just to be sure all has been done fine, open Visual Studio 2010 and create a new Windows Phone application. Once you selected the New Project option in the Start Page  you will be presented with a series of project types. For this first test select "Windows Phone Application". This is a minimal application for your phone and a good starting point for your training. Once Visual Studio has finished building the project it is displayed into the solution explorer. We will go deep in every file of the project in the next article, for now just locate the Grid called "ContentPanel" in the MainPage.xaml file and add inside it the following markup:

<TextBlock 
    Text="Hallo Windows Phone" 
    FontSize="32" 
    HorizontalAlignment="Center" 
    VerticalAlignment="Center" />
If you have the designer active you will see immediately the element you just added to the markup. If you want to see your application running just hit F5 and it will be deployed to the emulator and then it run as shown in the figure.

Capture1Surprisingly, also if your phone is connected your application runs on the emulator. By default when you create a new project it is set to deploy the projects to the emulator. To change this you have to search for a combo box in the middle top of the Visual Studio 2010 toolbar and you will find the option "Windows Phone 7 Device" to be selected in place of "Windows Phone 7 Emulator". Just remember always to have the phone connected, the Zune active and the phone lock screen opened then hit again F5 and the IDE will deploy the solution to the device and will starts the application attaching it for the debug. Now you can put breakpoints in your code and debug the application running into the device in an enviroment really easy and productive.

What's next?

The goal for this article was to put in place all the basics to make everyone that is reading, ready to follow the next, and more complicated, examples with a common knowledge base. We have started from a very very basic example, but now we are ready to make, the very first steps into the Silverlight programming for Windows Phone 7 as you expect.

 

About the Author

Andrea BoschinAndrea Boschin is 41 years old from Italy and currently lives and works in Treviso, a beautiful town near Venice. He started to work in the IT relatively late after doing some various jobs like graphic designer and school teacher. Finally he started to work into the web and learned by himself to program in VB and ASP and later in C# and ASP.NET. Since the start of his work, Andrea found he likes to learn new technologies and take them into the real world. This happened with ASP.NET, the source of his first two MVP awards, and recently with Silverlight, that he started to use from the v1.0 in some real projects.


Subscribe

Comments

  • ppopadiyn

    RE: Windows Phone 7 - Part #1: Getting Started


    posted by ppopadiyn on Feb 03, 2011 14:57

    Hi Andrea,

    First of all great series of articles. I have the following question. Do you know if it is possible to do private distribution of wp7 applications. For example, I want to develop applications that should be available only for the people from my company. I have lg and there are applications that are available only for the lg holders. Obviously this is possible for the manufactures. But is it possible for the common developers like me ?

  • -_-

    RE: Windows Phone 7 - Part #1: Getting Started


    posted by Andrea Boschin on Feb 03, 2011 15:07
    Unfortunately at the moment there is not any way to do what you asking. I think it is a point they have to solve asap because it is important for the success of the platform. But at the moment the WP7 device is to be considered consumer-only.
    bye
  • -_-

    Silverlight 4 Exam (70-506)


    posted by DR on Feb 23, 2011 05:03

    Is Blend is also part of Silverlight 4 Exam (70-506)? If yes, is it available in Express edition?

  • ppopadiyn

    RE: Windows Phone 7 - Part #1: Getting Started


    posted by ppopadiyn on Feb 28, 2011 14:25

    Hi again, :-)

    Are you planning to post an article demonstrating how to create a trial application ? I don't have any "know-how" in this area and wondering what are the best practices, are there any specifics (that have to be considered) when you design your application, etc.

  • -_-

    RE: Windows Phone 7 - Part #1: Getting Started


    posted by Andrea Boschin on Feb 28, 2011 15:04
    It is a good suggestion. Please send it to the team sending them an email or a tweet to @silverlightshow. Thanks
  • -_-

    RE: Windows Phone 7 - Part #1: Getting Started


    posted by Salam on Mar 07, 2011 09:04

    One of the best series of articles on Windows phone 7 programming.

    Thank you for sharing with us, really enjoyed reading it.

Add Comment

Login to comment:
  *      *       

From this series