Developer and designer tools introduced to iPhone application developers (Windows Phone 7) Part 2

Visual

Studio ships with a large number of snippets and developers can create their own library of snippets. They can also be indexed and searched using user defined terms.

Type ctrl+k ctrl+x to bring up the Insert Snippet prompt. Select Visual C#, followed by "i" to select a code snippet for "if statement", which will insert an if statement in the code.

tmpC-24

The inserted snippet identifies the parts the user needs to complete:

tmpC-25_thumb_thumb

Type the remaining code, so that the body of the method is as follows:

tmpC-26_thumb_thumb


Visual Studio supports various refactoring mechanisms. Select any piece of code and right click to access the refactoring menu.

The Visual Studio editor is highly customizable. Developers can easily define different keyboard shortcuts or create their own macros. Macros help you automate repetitive actions by combining a series of commands and instructions together, making it easy to invoke them as one command. iPhone application developers can easily customize the editor to use any shortcuts and keyboard combinations that they are familiar with. Instead of spawning a separate window for each file, as in XCode, the default view in VS uses tabbed windows. Developers can change this behavior to suit their need. They can change the way in which various windows are docked within the Visual Studio Shell.

Building Applications

Similar to XCode, Visual Studio Express for WP7 allows you to build the Visual Studio solution on demand. Further, each project that is part of the solution can be built separately.

Visual Studio uses an XML based, declarative build system called MSBuild which can be compared with Ant/Nant. Builds can be invoked interactively or via a command line for batch processing. This system is flexible and allows you to build a specific target either as a debug build or as a release build.

tmpC-27

Emulator

WP7 developer tools include an emulator that can be used effectively for testing applications. It provides features that are comparable to the iPhone simulator included in the iPhone developer tools.

The WP7 emulator provides a virtualized environment in which you can deploy, debug and test applications. The Windows Phone Emulator is designed to provide comparable performance to an actual device and meets the peripheral specifications required for application development. It can be invoked from Visual Studio to load an application package [.xap] within the emulator.

Debugging

Visual Studio Express Phone 7 includes a very powerful symbolic debugger that can be used with the WP7 emulator or with a remote device. Once the application breaks into the debugger, the developer can view the variables in the application and control the execution.

Let us look at the debugger in action. Press F5 to launch the application again. Type "napkins" in the textbox and click Add.

tmpC-28_thumb[2]

"Napkins" is added at the end of "Nothing here yet!" - not something we expected. In Visual Studio, click in the light blue area to the left of the "string tStr = txtltem.Text;" line in the code window. This will insert a breakpoint at that line.

tmpC-29_thumb[2]

Launch the application again using F5. When the application breaks into the debugger, hover over txtItem in the code and click "+" in the popup to view the variable txtItem, as shown below. The developer can view the variable, its type, its fields and properties. The picture below shows how you can walk up and down the type hierarchy to inspect the objects.

tmpC-30

You can set a "watch" on certain variables to inspect them continuously. Right click txtList, followed by Add Watch. The watch window will show the variable txtList. Expand txtList by clicking on "+".

tmpC-31

Step through the code using F10 to see that control does not enter the if statement.

tmpC-32_thumb[2]

Observe in the watch window that the value of txtList.Text is "Nothing here yet!", whereas it is getting compared with "Nothing here yet" (with no exclamation point.) Therein is our bug! Change that statement to add the exclamation point, as follows:

tmpC-33_thumb[2]

While in the debugger, the developer can use the VS ‘immediate mode’ where one can write managed code instructions to modify or view the variables or execute some code to help with debugging.

tmpC-34

Update the code and relaunch the application. Test it by adding couple of items to the shopping list.

tmpC-35_thumb[2]

Overall, you will find that, with the power of the managed programming environment, debugging a WP7 application is very easy. Unlike an XCode application, where you have access to assembly instructions, memory dumps and various registers, the WP7 application debugging is done entirely at the application level, using C# code and types.

In addition to the above debug facilities, the .NET framework includes two specific classes, Debug and Trace, that make it easy to write run-time debug messages to the output window. C# also supports an assert statement, which is evaluated at run time. If the statement evaluates to true, nothing happens, but if the statement returns false, the program breaks into a debugger.

Summary

The Windows Phone 7 developer toolset includes rich tools designed to support every step in the entire application development lifecycle. The design, development and testing tools are amenable to existing iPhone team roles and processes. The tight integration between theWP7 tools can help you streamline your design, development and testing workflow. These tools provide end-to-end functionality and are highly customizable, with the power to make your team quickly productive.

Next post:

Previous post: