Windows Phone 7 is released officially by Microsoft! I watched the Windows Phone 7 Launch Event and it was very nice 🙂 . In this article, I will explaining you about how you can develop the sample application for Windows Phone 7 in Visual Studio.
The Windows Phone 7 Developer Tools package includes everything you need to write awesome applications and even games for Windows Phone 7. All of the tools included in it are absolutely free.
The following are the tools that are installed with the download:
- Visual Studio 2010 Express for Windows Phone – Free edition of VS 2010 for Phone development.
- Express Blend 4 for Windows Phone – Free version of Blend for Windows Phone 7 Development.
- Silverlight for Windows Phone 7 – Rich framework for building great applications for Windows Phone 7.
- XNA Game Studio for Windows Phone 7 – Rich framework that enables you to build great 2D and 3D games for Windows Phone 7.
- Windows Phone Emulator – A hardware accelerated emulator that allows you to run and debug your applications and games without requiring a phone.
- Phone Registration Tool – When you get a device, this allows you to “unlock” the device so you can run/debug your application on it, using your Marketplace account.
All of the above tools and frameworks are packaged into one setup, and everything is free. If you already have Visual Studio 2010, the setup will also add support for Windows Phone 7 development and projects to your full Visual Studio 2010.
Using the Windows Phone 7 Tools
Building a Sample Windows Phone 7 Application
First make sure you’ve installed the Windows Phone Developer Tools CTP – this includes the Visual Studio 2010 Express for Windows Phone development tool (which will be free forever and is the only thing you need to develop and build Windows Phone 7 applications).
After you’ve downloaded and installed the Windows Phone Developer Tools CTP, launch the Visual Studio 2010 Ultimate for Windows Phone that it installs or launch the VS 2010 RC (if you have it already installed), and then choose “File”->”New Project.” Then select the “Silverlight for Windows Phone”. The first CTP offers two application project templates. The first is the “Windows Phone Application” template – this is what I am using for this sample application. The second is the “Windows Phone List Application” template – which provides the basic layout for a master‑details phone application:
After creating a new project, you’ll get a view of the design surface and markup. Notice that the design surface shows the phone UI, letting you easily see how your application will look while you develop. For those familiar with Visual Studio, you’ll also find the familiar ToolBox, Solution Explorer and Properties pane. Nothing to tell in advanced about them 😀
For this sample application, we’ll start out by adding a TextBox and a Button from the Toolbox. Notice that you get the same design experience as you do for Silverlight on the web or desktop. You can change the properties using the properties pane. I have changed the name of the TextBox that we added to username and the page title text to “Hello world.”
We can write the code by double‑clicking on the button and create an event handler in the code-behind file (MainPage.xaml.cs).
We’ll start out by changing the title text of the application. The project template included this title as a TextBlock with the name textBlockListTitle (note that the current name incorrectly includes the word “list”; that will be fixed for the final release.) As we write code against it we get intellisense showing the members available. Below we’ll set the Text property of the title TextBlock to “Hello “ + the Text property of the TextBox username:
We now have all the code necessary for a Hello World application. We have two choices when it comes to deploying and running the application. We can either deploy to an actual device itself or use the built‑in phone emulator:
Because the phone emulator is actually the phone operating system running in a virtual machine, we’ll get the same experience developing in the emulator as on the device. For this sample, we’ll just press F5 to start the application with debugging using the emulator. Once the phone operating system loads, the emulator will run the new “Hello world” application exactly as it would on the device:
The orientation buttons allow us easily see what the application looks like in landscape mode (orientation change support is just built into the default template).
Note that the emulator can be reused across F5 debug sessions – that means that we don’t have to start the emulator for every deployment. We’ve added a dialog that will help you from accidentally shutting down the emulator if you want to reuse it. Launching an application on an already running emulator should only take ~3 seconds to deploy and run.
Within our Hello World application we’ll click the “username” textbox to give it focus. This will cause the software input panel (SIP) to open up automatically. We can either type a message or – since we are using the emulator – just type in text. Note that the emulator works with Windows 7 multi-touch so, if you have a touchscreen, you can see how interaction will feel on a device just by pressing the screen.
We’ll enter “Hrushi” in the textbox and then click the button – this will cause the title to update to be “Hello Hrushi”:
We provide the same Visual Studio experience when developing for the phone as other .NET applications. This means that we can set a breakpoint within the button event handler, press the button again and have it break within the debugger:
So, try this and if any problem you faced, ping me…Comments are always welcome.. So till then,
Enjoy and keep imagining ! 😀