SDK Getting Startet

Page 1

Department of Telecommunications & Internet Technologies

Lecture Note

MOBILE COMPUTING PHONE 7

Version: 2.1 Date:

2011-09-22

Author: DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

TABLE OF CONTENTS:

1 Overview ................................................................................................................................. 3 1.1 Topic and goal of lesson................................................................................................... 3 1.2 Audience and preconditions ............................................................................................. 3 2 Installation and introduction.................................................................................................... 4 2.1 Introduction ...................................................................................................................... 4 2.1.1 Silverlight .................................................................................................................. 4 2.1.2 XNA .......................................................................................................................... 4 2.1.3 Push Notification Service .......................................................................................... 4 2.2 Installation ........................................................................................................................ 5 3 Hello World ............................................................................................................................. 8 3.1 Project setup ..................................................................................................................... 8 3.1 Finding Errors ................................................................................................................ 12 3.2 Windows Phone 7 Emulator ........................................................................................... 12 3.1 Debugging ...................................................................................................................... 13 4 References ............................................................................................................................. 15

page 2 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

1 OVERVIEW 1.1 Topic and goal of lesson This lecture note is a tutorial for getting started with programming on the Windows Phone 7 platform. This document should help you to get started, set up the development environment and write some simple and basic code. The lecture note won’t give you all details about each framework.

The lecture note is primarily based on documents and resources from the official Windows Phone 7 developer page at: http://msdn.microsoft.com/library/ff402531(VS.92).aspx

1.2 Audience and preconditions The lecture is targeted to students of the “University of Applied Sciences in Bachelor and Master degree programs. A good understanding of object oriented programming is required.

page 3 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

2 INSTALLATION AND INTRODUCTION 2.1 Introduction Windows Phone 7 is the successor of the Windows Mobile platform and was launched in 2010. It is designed for the consumer market unlike its predecessor Windows mobile which was designed for the enterprise market. Applications are sold and deployed on the Windows Phone Marketplace, which provides registration services and certifies that programs meet minimum standards of reliability, efficiency, and good behavior. Apps are compiled in a .xap file which is actually a .zip file which contains all the files necessary for the application. Programs for Windows Phone 7 are written in .NET managed code. It is possible to write Windows Phone 7 applications in Visual Basic and C# .NET. The free downloadable IDE Microsoft Visual Studio 2010 Express for Windows Phone includes an on-screen phone emulator. Windows Phone 7 supports 2 popular programming frameworks: Silverlight and XNA.

2.1.1 Silverlight For writing utilities or applications Silverlight is used in most cases. These programs are built from a combination of markup and code. The markup is the Extensible Application Markup Language, or XAML which describes the user interface.

2.1.2 XNA Microsoft XNA is used to develop 2d and 3d games, the name originated out of the project's development name "Xbox New Architecture" and encompasses Microsoft's entire Game Development Sections. For 2D games sprites and backgrounds based on bitmaps are used, 3D games require the definition of models in 3D space.

2.1.3 Push Notification Service If an application is running on Windows Phone 7 and a new application is started the first one gets into sleep mode. While an application is in sleep mode, it won't react on external events, in case of a messenger app it won't react on incoming chat messages. To reactivate applications, the Microsoft Push Notification Service is used. A server can send a notification to the Push Notification Service which in turn routes the push notification to the application running on a Windows Phone device. This is similar to the APNS (Apple Push Notification Services) that was used on iOS before the introduction of multitasking / backgrounding support. page 4 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

2.2 Installation 1. Download and install Visual Studio 2010 2. Optionally you can download MS Expression Blend 3. Download the Windows Phone Developer Tools At: http://www.silverlight.net/getstarted/devices/windows-phone/ 4. Install the Phone Developer Tools Now it is possible to work with the Emulator integrated in Visual Studio. If you like to use a real phone you have to: 1. Download and Install Zune (http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ab1a80e d-e337-4346-9d5a-f00cfb467514) 2. Get a free Developer Account at: https://www.dreamspark.com/default.aspx (you will need a key from your lecturer to sign in for free) 3. Register Phone with: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\Phone Registration\PhoneReg.exe 4. Register with your windows live ID and follow the information on the screen Figure 2-1 shows the different areas of the IDE (integrated development environment). Area 1 shows the GUI Designer. Here it is possible to drag and drop GUI elements from the Toolbox (left side, or selection via View: Toolbox) and to handle basic design issues. If you like to have a more comfortable tool to edit the GUI via drag and drop the best solution would be to install the MS Expression Blend Tool. Area 2 shows the XAML Code which represents the GUI elements in XML style. If you do some changes in the GUI Designer the XAML code also changes (and via versa). It is also possible to drag elements from the Toolbox into the XAML code. The XAML code is an XML representation of the GUI and the interface between designer and developer. So the XAML file does not contain logic, except event handlers which trigger some actions, for example if a button is pressed. The Project Area (3) contains all the files which are part of the project. To add new files right click on the project name and select Add => New Item.

page 5 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

Figure 2-1: Project areas in Visual Studio

The Project Area (also called Solution Explorer) contains the files and Documents. We shortly addressed the GUI Designer and the XAML view as an interface between designer and developer, but did not discuss the place to enter all the logic. Figure 2-2 shows the XAML file (extention *.xaml) and the code behind file (extension .xaml.cs). The Code Behind file contains the logic (if you are more familiar with programming Phone7 devices you will see, that it is better to use several patterns to separate logic and view instead of writing the code directly into the code behind file).

page 6 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

Figure 2-2: Code Behind file

page 7 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

3 HELLO WORLD 3.1 Project setup After installing the required components, open the Visual Studio IDE and use the “New Project” wizard to create a new Windows Phone project. 1. Select File - New - Project. 2. Select now the "Silverlight for Windows Phone" in the installed templates list. 3. Next select the "Windows Phone Application" type 4. Enter an application name and click Ok.

Figure 3-1: "New Project" wizard

Now the first project is ready, on the lift side the visual representation of the user interface is displayed (MainPage.xaml). In the middle you can see the markup of the user interface in XML format. The Solution Explorer on the right side displays all files which belong to the new project, see Figure 3-2.

page 8 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

Figure 3-2: HelloWorld.xaml in Visual Studio

To show the source code of the application open the "MainPage.xaml.cs" file in the Solution Explorer or right-click on the "MainPage.xaml" and go to "View Code".

Figure 3-3: HelloWorld.xaml.cs in Visual Studio page 9 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

The first lines beginning with "using" define Namespaces which are required to run the application. System Namespaces contain base classes, for example fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers. The entry point of the application is the constructor "MainPage()", and in this constructor the method "InitializeComponent()", which builds the user interface. Code which shall be executed at the start of the application can be inserted after that line. To set the page title add "PageTitle.Text = "Hello World";" after "InitializeComponent()".

Figure 3-4: Set PageTitle

To compile the Application you can press F6, to compile and start the application press F5. As default setting the device emulator is used. To change this, select the proper target as shown in Figure 3-5.

Figure 3-5: Compiling the App for emulator or device

page 10 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

The device only works, if it is registered as a developer device as described in chapter one. To add graphical user elements open the "MainPage.xaml" file and move the mouse to the toolbox which is located at the left top in Visual Studio. From the Toolbox drag a Button and a TextBlock into the "MainPage.xaml" - Layout.

Figure 3-6: Button and TextBlock

Visual Studio provides an easy way to add click-events, simply double-click on the button and the source code with the new click-event will be displayed. To change the text of the TextBlock when the Button is clicked add the line "textBlock1.Text = "My first Windows Phone 7 App";" inside the click-event.

page 11 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

Figure 3-7: Click-Event in Windows Phone 7

3.1 Finding Errors Errors in the source code are listed in the Error List which is located at the bottom in Visual Studio. By clicking on the error Visual Studio will show the source line where something is wrong.

Figure 3-8: Error List in Visual Studio

3.2 Windows Phone 7 Emulator Windows Phone 7 Emulator is simply a desktop application which emulates a Windows Phone 7 device. It is designed to provide comparable performance to an actual device, the following features can be tested:  

Device peripherals Processor, RAM, display, and graphics processing unit (GPU) page 12 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc          

Persistent data store Web services Networking Media playback Keyboard input Deployment experience Tombstoning Location data Accelerometer data Language and region settings

If you want to test the behavior of your application at screen rotations, the Rotate buttons on the emulator can be used to rotate the emulator’s screen.

Figure 3-9: Rotate Button in Windows Phone 7 Emulator

3.1 Debugging The easiest way to debug applications is to set breakpoints in the source lines you want to analyze (Figure 3-10). If the compiler reaches a breakpoint during execution it will stop at that line (Figure 3-11).

Figure 3-10: Breakpoint in Visual Studio

page 13 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

Figure 3-11: Visual Studio, Compiler at Breakpoint

If you want to keep an eye on several variables during debugging the Watch window can be used. For adding a variable to the Watch window right-click it and go to "Add Watch".

page 14 of 15


Mobile Computing – Phone 7 Getting Started DI(FH) Stefan Schmidt, MSc Ronald Bruckner, MSc

4 REFERENCES [Fuc09]

Fuchß, T.: „Mobile Computing“, 2009, ISBN 978-3-446-22976-1, Hanser Verlag

[Lee11]

Lee, H.; Chuvyrov, E.: "Beginning Windows Phone 7 Development", 2011, ISBN 978-1-430-23596-5, Apress Verlag

http://msdn.microsoft.com/library/ff402531(VS.92).aspx

page 15 of 15


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.