Windows Phone

Writing Your First Phone Application - Adding Code (part 2)

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
11/25/2010 3:37:00 PM

Debugging with a Device

If you have a phone with which you want to do your development, you will want to be able to deploy and debug directly on the phone itself. First you need to connect your phone to your development machine. The communication with the phone is all routed through the Zune software. By connecting your device to your computer, you should also run Zune (if it fails to run automatically). While the device will continue to operate normally when connected to Zune, there are several functions which are disabled to allow for Zune to synchronize media (music, photos and videos) to the device. Consequently these functions are using your media on the phone. Once connected, the device looks like it would normally (as seen in Figure 4).

Figure 4. Connected Device (phone.jpg)

All the communication that you will do to your phone (e.g. debugging, deploying and registration) is all done while the Zune software is running. Once you’ve connected your phone to your computer and run the Zune software, you should be able to see the phone attached as shown in Figure 5.

Figure 5. Your Phone Connected to the Zune Software (ZuneWithPhone.bmp)

Once your device is connected, you can use it to sync your music, videos and photos to the phone. Though, before you can use a phone as a development device, you will need to register the phone for development. This lifts the requirements that applications that are signed by Microsoft. This allows you to deploy your applications directly to the phone so you can debug applications.

Before you can enable your phone as a developer phone, you will need to have an account at the Windows Phone developer portal[1]. Once you have done that, you can enable your phone to be used for development. To do this you will need the tool called “Windows Phone Developer Registration”. This tool is installed when you install the Windows Phone 7 SDK. When you run this application it will ask you for your Windows Live ID that you used to register with the developer portal as shown in Figure 6.


Figure 6. Registering your Device (DeveloperPhoneRegistration.bmp)

If your phone is successfully attached to your computer, the Status will tell you that it is ready to register your device for development. At this point, just hit the ‘Register’ button to register with the developer portal. Once it registers the phone, it changes the status to show you that the phone is ready (as shown in Figure 7).

Figure 7. Successfully Registered Developer Phone (DeveloperPhoneRegistrationComplete.bmp)

Once you’ve registered your device, you can deploy and debug your applications using Visual Studio. The key to using the device instead of the emulator is to change the deployment using the drop-down list of deployment options. There are only two:

  • Windows Phone 7 Emulator

  • Windows Phone 7 Device

The drop-down is located in the toolbar of Visual Studio as shown in Figure 8.

Figure 8. Changing the Deployment to use a Development Phone (DebuggingOnDevice.bmp)

Once you change the deployment target you can debug just like you did with the emulator. When you run the application, it will deploy your application to the device and run it so you can debug it in the same way as you did with the emulator. Figure 9 shows the application running on a device.

Figure 9. Running on a Device (DeviceDebugging.jpg)

Using Touch

Even though the touch interactions do, in fact, fire mouse events there are other events which allow you to design your application for touch. Since touch is so important to the way that applications on the phone work, this first application should give you a taste of that experience. To show touch working, let’s add an ellipse to the application that the user can move around by dragging it with their finger. To get started, you should open the MainPage.xaml file and add a new ellipse in the center of the page. To do this find the TextBlock called theStatus and place a new Ellipse element after it like so:

<Grid x:Name="ContentGrid"
<Rectangle Fill="#FF7E0505"
RadiusX="24" />
<TextBlock HorizontalAlignment="Center"
Name="theStatus" />
<Ellipse x:Name="theEllipse"

We want to be able to move theEllipse as the user drags it. To allow us to do this we will need to use something called a Transform. In Silverlight, a Transform is used to change the way that an object is rendered without having to change properties of the Ellipse. While we could change the margins and/or alignments to move it around the screen, using a transform is much simpler. You should use a TranslateTransform to allow this movement. A TranslateTransform provides an X and Y property which specify where to draw the element (as a delta between where it originally exists and where you want it). You can specify this transform by setting the RenderTransform property with a TranslateTransform (naming it in the process):

<Ellipse x:Name="theEllipse"
<TranslateTransform x:Name="theMover" />

Now that we have a way to move our Ellipse around the page, let’s look at dealing with touch. In Silverlight, there are two specific types of touch interactions that are meant to allow the user to change on-screen objects. These are when the user drags their finger on the screen and when they use a pinch move to resize objects. These types of interactions are called Manipulations. Silverlight has three events to allow you to use this touch information:

  • ManipulationStarted

  • ManipulationDelta

  • ManipulationCompleted

These events let you get information about the manipulation as it happens. For example, lets handle the ManipulationDelta event to get information about when the user drags on the screen. This event is called as the manipulation happens and included information about the difference between the start of the manipulation and the current state (e.g. how far as the user dragged their finger):

public partial class MainPage : PhoneApplicationPage
// Constructor
public MainPage()

theStatus.Text = "Hello from Code";

theStatus.MouseLeftButtonUp +=
new MouseButtonEventHandler(theStatus_MouseLeftButtonUp);

theEllipse.ManipulationDelta +=
new EventHandler<ManipulationDeltaEventArgs>(

void theEllipse_ManipulationDelta(object sender,
ManipulationDeltaEventArgs e)
// As a manipulation is executed (drag or resize), this is called
theMover.X = e.CumulativeManipulation.Translation.X;
theMover.Y = e.CumulativeManipulation.Translation.Y;


The event is fired while the user either pinches or drags within theEllipse.. In this case the code is only concerned with the dragging. In the event handler for ManipulationDelta, the ManipulationDeltaEventArgs object contains information about the extent of the manipulation. In the CumulativeManipulation property of the event args, there is a property called Translation which contains the extent of the drag operation (the complete delta). We are just changing theMover’s properties to match the manipulation. This means we can now drag theEllipse around and see it change position under our dragging as seen in Figure 10.
Figure 10. Dragging the Ellipse (DraggingEllipse.bmp)

Other -----------------
- Developing Applications for Windows Phone 7 : Designing with Blend
- Developing Applications for Windows Phone 7 : Creating a New Project
- Developing Applications for Windows Phone 7 with Silverlight : Preparing Your Machine
- Windows Phone 7 : Picking Ringtones and Alerts
- Windows Phone 7 : Changing Themes and Wallpaper
- Windows Phone 7 : Customizing the Start Screen
- Windows Phone 7 : Connecting to a Wi-Fi Hotspot
- Windows Phone 7 : Setting Up Facebook
- Windows Phone 7 : Setting Up E-Mail and Your Calendar
- Windows Phone 7 : Taking a Quick Tour (part 2)
- Windows Phone 7 : Taking a Quick Tour (part 1)
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS