How to set up smartphones and PCs. Informational portal
  • home
  • Advice
  • Development of the first application for Windows Phone: Preparing the working environment. Your own Windows Phone app? Easy

Development of the first application for Windows Phone: Preparing the working environment. Your own Windows Phone app? Easy

  • Translation

Developing apps for the Windows Phone 7 platform is more like developing for the Android platform than you might expect. In this article, Chris Bennett explores the similarities between the two platforms.

Differences between platforms

Before diving into the specific tools and processes for porting and / or building applications for Windows Phone 7, let's start with the terminology and technological differences between Windows Phone 7 and Android. The first big difference is that Windows Phone 7 apps are built as .NET managed assemblies written in C #. The platform supports two types of applications: Silverlight and XNA games.
Most Windows Phone 7 apps are built using Silverlight, which provides a form-based way to interact with the user through standard controls such as text boxes, text boxes, lists, and more. The Silverlight counterpart for Android Layout and its accompanying Activity is Page.
Another type of application supported by Windows Phone 7 is XNA, which allows developers to create 2D and 3D games. It is the Android SurfaceView and GLSurfaceView equivalent for 2D and 3D respectively. Unlike Android, which focuses on using OpenGL for games, XNA games use Direct3D, which makes it easier to port games from PC and Xbox 360 platforms.

Pages and Navigation

Silverlight Pages are created as XML files, just like Android Layouts. The XML file uses XAML (Extensible Application Markup Language) to describe the Page. XAML is similar to Android Layout, but with a broader range of capabilities. XAML allows developers to implement Page actions, including animations, data binding, and more, thus reducing the amount of code required.
Android Layout is decoupled from the Activity used to perform actions. As a result, you are forced to write code in order to associate the Activity with the corresponding user interface (UI) elements. The C # code for a specific Page is already tied to the UI elements and there is simply no such need. The framework automatically creates the necessary "bindings" for objects and events for the Page and user interface. This prevents the clutter that usually occurs in the OnCreate method of every task, where you create UI bindings and various required handlers.
Navigation is another major difference between platforms. In Android, you switch from one task to another by creating an Intent. The Windows Phone 7 counterpart is Navigation, which lets you navigate between different Pages. As with Android Intent, you can pass data to the Page you navigate to. Page in Windows Phone 7 has some properties similar to ASP.net Page. For example, a QueryString is commonly used to pass information to the next Page.

Convert Layouts to Pages

Before diving into the code, we need to look at converting Android Layout XML to Windows Phone 7 XAML Pages. Of course, one of the great things about free tools for Windows Phone 7 is the quality of the design tools available for XAML. The XAML designer included in Visual Studio 2010 is intended to be used primarily by developers to get the basic controls for a Page and start developing. Expression Blend is designed to create professional designs with a more advanced set of tools to enhance the user interface. As with Android Layout, you can always resort to editing the XAML directly in the text editor, as this is a regular XML file.
Windows Phone 7 Page provides layout and controls similar to Android Layout. The following table shows counterparts for both platforms.
Markup elements
Note that Windows Phone 7 has one-to-one correspondences for basic markup and controls. But for some of the specialized markup and control elements, there is no correspondence. The reason for this lies in the richness of XAML, which makes it very easy to nest controls within each other. This way you can, for example, add a ListBox with CheckBoxes next to each item without having to write any code. This means that you don't need all those complex bundled controls, they can be created and modified within your application.

Data storage

Data storage is a big part of the task when developing most mobile applications. In Windows Phone 7, the idea is to use cloud services as the primary storage medium. At first glance, this may seem a little strange to you, but if you are creating a client application for your site, it makes sense. If you are not going to go this route, then you have two options: use commercial services for storage, such as Windows Azure, or use the local IsolatedStorage interface. IsolatedStorage allows you to store files for use only by your application.
Depending on how your applications store data, you might want to store data locally without having to create and use a database. For example, if you are creating an RSS / Podcast application, you can simply store the XML from the RSS feed. If you need to access data, just load the data and use LINQ (Language Integrated Query) to get specific data.
In the RSS application example, we can either work with the original XML from the RSS feed, or we could use LINQ to XML to create an XDocument to hold the entries, as shown below:
  1. // Create XML
  2. XDocument doc = new XDocument ();
  3. doc.Add (new XElement ("DataRoot",
  4. new XElement ("Record",
  5. new XElement ("value", "data1")),
  6. new XElement ("Record",
  7. new XElement ("value", "data2"))

The XML generated by this simple piece of code looks like this:
  1. < DataRoot >
  2. < Record >
  3. < value >data1
  4. < Record >
  5. < value >data2
* This source code was highlighted with Source Code Highlighter.

To store this XML in Isolated Storage, we use IsolatedStorageFile with IsolatedStorageFileStream as shown in the following snippet:
  1. // Save the XML
  2. doc.Save (file);
  3. file.Close ();
* This source code was highlighted with Source Code Highlighter.

As you can see, it is very easy to implement XML data storage in isolated storage. The code to get the XML and create a LINQtoXML query is shown below:
  1. // Load the XML
  2. using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ())
  3. using (IsolatedStorageFileStream file = isf.OpenFile ("data.xml", FileMode .OpenOrCreate))
  4. XDocument d = XDocument .Load (file);
  5. var query = from r in d.Root.Elements ("Record")
  6. select r;
  7. // Process the list of record
* This source code was highlighted with Source Code Highlighter.

Although the above example is very simple, it illustrates how easy it is to implement data storage on a phone without having to create and use a database. This code can also be extended to store more complex data.

Development tools

As an Android developer, you are most likely used to the good and bad sides of open source development. Using the Eclipse IDE for Android is, of course, part of the good side. But the Android Development Toolkit (ADT) lacks many essential tools, such as proper markup tools. While ADT does provide similar tools, they are not robust enough for you to easily generate markup — you will most likely have to dive into XML.
Microsoft has provided robust development tools for many years. And the Windows Phone 7 platform is no exception. Microsoft, as usual, makes it easy and inexpensive to get started right away. Java developers can download and try these tools without spending any money.
The following tools are currently available at create.msdn.com:
  • Microsoft Visual Studio 2010 Express for Phone
  • Microsoft Expression Blend for Phone
  • Microsoft XNA Game Studio for Phone
These three tools will get you started building Windows Phone 7 apps for free.
Microsoft Visual Studio 2010 Express for Phone is the primary integrated development environment (IDE) used to create applications for Windows Phone 7. It includes all the tools you need to create applications, including a Page markup tool, a C compiler. #, Windows Phone 7 emulator and more.
Microsoft Expression Blend for Phone is a tool aimed primarily at professional designers and is used to enhance Pages in a Silverlight application. Developers can use this tool to create pages from scratch or enhance the Pages of an existing application without affecting its code.
Microsoft XNA Game Studio for Phone provides the set of tools needed to create 2D and 3D games for the platform. Studio also includes the XNA Framework, as well as the tools needed to include the audio and graphics needed to create loop-based games.

Conclusion

Windows Phone 7 offers a fresh take on the smartphone operating system, but it is still based on proven technologies such as Silverlight, WPF, C # and many more. As you can see from this article, the differences between Android and Windows Phone 7 are not that great.

UPD: I have published a translation of this article to show that learning development for the Windows Phone 7 platform is not so difficult if you already have experience in development for Android. It does not say whether any of these mobile platforms are better or worse.
Please, do not drive my karma into negative so that I can publish other articles on development for Windows Phone 7. If you are not interested, pass by, do not deprive those who are interested in the opportunity to learn something new.

Before starting the process of developing applications for mobile phones running on, you should prepare a special toolkit, without which it will be impossible to complete further stages.

Preparation for development requires the following software:

  • Visual Studio2010

This software provides the ability to fully use the debugs. It is worth noting that similar layouts are used for desktop versions of Windows.

  • Expression Blend

The software is a visual designer, thanks to which you can easily work with layers, all kinds of templates, style and animation. Expression Blend4 for WindowsPhone is available as a free download. It's worth noting that Expression Blend is the base for the XAML.

  • WindowsPhone SDK

With this package, you can start the development process.

  • WindowsPhone Emulator

Allows you to create in an emulator with built-in Internet Explorer9, equipped with HTML5, applications. It can also be used to test calls and SMS messages, as well as support many useful functions, including multitouch on monitors, camera simulation. Geolocation services are available for use. However, this emulator lacks support for Zune media.

  • XNA Game Studio4.0

Thanks to this software, you can develop games, both for the console, PC, and for WindowsPhone. XNA Framework libraries are an important piece of software that is characterized by the presence of managed code.

Additional software

Additional tools for developers include the following:

  • WindowsPhone Developer Registration Tool.
  • WindowsPhone Profiler. It detects performance problems.
  • Silverlight Toolkit for WindowsPhone.

Development environment features

Once all the required tooling is installed, developers have access to numerous Silverlight for WindowsPhone application templates. This software includes both a full set of technological components for development and Windows 8-style UI, which is an effective concept for the design of the interface and system that allows you to interact with the user at a high level. With its help, you can create a memorable and original style that will really make the application stand out from many others in the store.

There are three templates that represent three different styles for WindowsPhone:

  • The first template is called WindowsPhone Application, which is a common example of a dialog application. Interaction with users is carried out using a single screen.
  • WindowsPhone Pivot Application is created as an application with bookmarks. Each of the bookmarks has its own title, by which you can identify the content. Pivot is used as a control element.
  • WindowsPhone Panorama Application has a peculiar system of interaction with users, which is carried out through zones with horizontal scrolling divided into panels. This template is characterized by the placement of the background image throughout the panorama. Content placed on the adjacent panel on the right side can be seen when displaying the current one. Panorama is a management element.

It is worth noting that templates ending in Agent are templates for special libraries, the main purpose of which is to perform various background tasks. There are also a huge number of different other templates that play an important role in the development process of various mobile applications.

You can learn more about developing applications for Windows Phone .

Before you start exploring the platform's capabilities and application development, you need to make sure that we have all the necessary tools and understand some of the basics of development.

Tools

Visual Studio 2010

To develop for Windows Phone you need Visual Studio 2010 with Service Pack 1 Professional edition or higher. If you do not have Visual Studio 2010, when you install the Windows Phone Development Toolkit, the free version of Visual Studio 2010 Express for Windows Phone will be automatically installed, on which you can also develop applications for Windows Phone.

Both versions of the Visual Studio IDEs provide the developer with full device and emulator debugging capabilities similar to those found in desktop Windows application developers.

Please note that in order to debug on a device, in addition to the device itself and a cable for connecting to a computer, you must have Zune software installed on your computer (http://zune.net). Also, before deploying the application and debugging, you need to register the device ("unlock" it) using the Windows Phone Developer Registration Tool, which is installed along with the Windows Phone SDK.

Windows Phone SDK

This package, available for download from the App Hub site http://create.msdn.com, contains everything you need to get started developing. At the time of this writing, the latest version of the toolkit is available in Windows Phone SDK 7.1 Release Candidate under a "Go Live" license with the ability to develop custom applications and publish them to the Windows Phone Marketplace. Windows Phone SDK 7.1 Release Candidate contains the following components:

  • Windows Phone SDK 7.1
  • Windows Phone Emulator
  • Windows Phone SDK 7.1 Assemblies
  • Silverlight 4 SDK and DRT
  • Windows Phone SDK 7.1 Extensions for XNA Game Studio 4.0
  • Expression Blend SDK for Windows Phone 7
  • Expression Blend SDK for Windows Phone OS 7.1
  • WCF Data Services Client for Windows Phone
  • Microsoft Advertising SDK for Windows Phone

If you do not have Visual Studio 2010 Professional Edition, Expression Bland 4 or XNA Game Studio 4.0 installed, the installation process will also download and install:

  • Visual Studio 2010 Express for Windows Phone
  • Expression Blend 4 for Windows Phone
  • XNA Game Studio 4.0

Expression Blend and Expression Blend for Windows Phone

Expression Blend is an interactive visual designer for XAML, an interface description technology for Silverlight applications and Windows Presentation Foundation (WPF). It's a great authoring tool that lets you easily manipulate layers, animations, styles, and templates. It is a basic XAML development tool. Expression Blend itself is not free, but a special version for creating applications for Windows Phone called Expression Blend 4 for Windows Phone is available for developers for free. It will be downloaded and installed during the Windows Phone SDK installation if you do not have the full version of Expression Blend on your computer. Read more about Expression Blend 4 on MSDN:

XNA Game Studio 4.0

Windows Phone Emulator

Although the Windows Phone Emulator does not contain the complete set of applications available on a real device, it provides a powerful framework that allows you to almost completely develop an application in an emulator.

Windows Phone Emulator does not support playing Zune media. The emulator only comes with one built-in Internet Explorer app, but that's Internet Explorer 9 with HTML5 support.

At the same time, the emulator allows you to test calls and sending SMS messages, supports multitouch on monitors with its support, supports simulation of a camera, geolocation services and an accelerometer, and also allows you to take screenshots.

Additional developer tools

Windows Phone Developer Registration Tool

Windows Phone Profiler

The Windows Phone Profiler is available from the Debug menu of Visual Studio with the Windows Phone SDK installed.

Silverlight Toolkit for Windows Phone- A collection of useful Silverlight controls for Windows Phone with design mode support, from the Silverlight development team. All source code, examples and documentation are available. Updated approximately every three months, available at http://silverlight.codeplex.com or via NuGet.

The current release includes controls such as ContextMenu, DatePicker and TimePicker, ToggleSwitch, WrapPanel, and GestureHelper.

Development environment

After installing the Windows Phone SDK Development Kit, the Project Groups for Silverlight for Windows Phone will appear in the New Project dialog in Visual Studio:

and projects for Windows Phone will be added in the XNA Game Studio 4.0 group:

This article series focuses on Windows Phone development with Silverlight, so let's take a closer look at the templates available to an application developer.

After installation, the developer has the following Silverlight for Windows Phone application templates at his disposal:

  • Windows Phone Application
  • Windows Phone Databound Application
  • Windows Phone Class Library
  • Windows Phone Silverlight and XNA Application

Before moving on to application templates, I need to say a few words about Windows Phone and Windows 8-style UI.

Windows Phone and Windows 8-style UI

Windows Phone isn't just another mobile platform. It contains not only a technological component, but also a fully developed concept of interface design and user interaction called Windows 8-style UI or Windows 8-style UI.

If you're a designer or have a dedicated designer on your team, you can take full advantage of the Expression Blend 4 or Expression Blend for Windows Phone tools that come with the Windows Phone SDK.

What if you are a developer and do not want to do visual design of an application, for example, you are developing a business application and all that is required of it is to match the overall design and style of Windows Phone?

Everything is very simple. First, Silverlight for phone is designed with Windows 8-style UI in mind, so all built-in controls are designed in Windows 8-style UI. Second, by default, applications built from templates provided with the Windows Phone SDK work, look, and use styles and fonts in accordance with the Windows 8-style UI.

On the other hand, the styling capabilities of XAML-based controls and applications that Silverlight provides are enough to make your application unique and recognizable while remaining within the Windows 8-style UI.

Interface Design and User Experience Guidelines for Windows Phone can be found at the following link

All that has been said above applies, of course, to the design of ordinary applications, since the requirements for the design of gaming applications and their interface may differ significantly. At the same time, we should not forget about the general principles of user interaction, embedded in the concept of Windows Phone.

Application templates

First, let's look at three templates that represent the three main styles of a Windows Phone application:

  • Windows Phone Application
  • Windows Phone Pivot Application
  • Windows Phone Panorama Application

Windows Phone Application is an analogue of a simple dialog application that has one main screen through which the main user interaction takes place.

Windows Phone Pivot Application is akin to a bookmarked application, where the title of each bookmark defines the content. A typical use case is that each bookmark represents the same data in general, but in different views and / or with different filtering. For example, calendar, email client and phone settings. The template uses a Pivot control.

Windows Phone Panorama Application - a panorama application in which the user interaction zones are also divided into panels, but they are accessible through horizontal scrolling; the background image is set to the entire panorama at once, it has a common title that scrolls slower than the panels; the content of the adjacent panel on the right is visible when the current one is displayed. For example, hubs in Windows Phone are implemented this way: People, Marketplace, Pictures, Music + Videos, etc. The template uses the Panorama control.

The templates ending in Agent are library templates for performing the corresponding background tasks:

  • Windows Phone Audio Playback Agent
  • Windows Phone Audio Streaming Agent
  • Windows Phone Scheduled Task Agent

Windows Phone Databound Application Template - A simple combo box application template - a detailed view that implements navigation between pages, passing parameters and storing data in the global ViewModel.

Windows Phone Class Library Template - A class library template for Windows Phone.

A Windows Phone Silverlight and XNA Application template for a Silverlight application that can use XNA to render graphical content.

Before you start exploring the platform's capabilities and application development, you need to make sure that we have all the necessary tools and understand some of the basics of development.

Tools

Visual Studio 2010

To develop for Windows Phone you need Visual Studio 2010 with Service Pack 1 Professional edition or higher. If you do not have Visual Studio 2010, installing the Windows Phone Development Toolkit will automatically install the free version of Visual Studio 2010 Express for Windows Phone, on which you can also develop applications for Windows Phone.

Both versions of the integrated development tools Visual Studio provide the developer with full debugging capabilities on the device and on the emulator, the same as the developers of applications for the desktop version of Windows.

Please note that in order to debug on a device, in addition to the device itself and the cable for connecting it to the development computer, you must have the Zune software installed on the computer with development tools (http://zune.net). Also, before deploying the application and debugging, you need to register the device or "unlock" using the Windows Phone Developer Registration Tool, which is installed along with the Windows Phone SDK.

Windows Phone SDK

This package, available for download from the App Hub site http://create.msdn.com, contains everything you need to get started developing. At the time of this writing, the latest version of the toolkit is available in Windows Phone SDK 7.1 Release Candidate under a "Go Live" license with the ability to develop custom applications and publish them to the Windows Phone Marketplace. Windows Phone SDK 7.1 Release Candidate contains the following components:

  • Windows Phone SDK 7.1
  • Windows Phone Emulator
  • Windows Phone SDK 7.1 Assemblies
  • Silverlight 4 SDK and DRT
  • Windows Phone SDK 7.1 Extensions for XNA Game Studio 4.0
  • Expression Blend SDK for Windows Phone 7
  • Expression Blend SDK for Windows Phone OS 7.1
  • WCF Data Services Client for Windows Phone
  • Microsoft Advertising SDK for Windows Phone

If you do not have Visual Studio 2010 Professional Edition, Expression Bland 4 or XNA Game Studio 4.0 installed, the installation process will also download and install:

  • Visual Studio 2010 Express for Windows Phone
  • Expression Blend 4 for Windows Phone
  • XNA Game Studio 4.0

Expression Blend and Expression Blend for Windows Phone

Expression Blend is an interactive visual designer for XAML, an interface description technology for Silverlight applications and Windows Presentation Foundation (WPF). It's a great authoring tool that lets you easily manipulate layers, animations, styles, and templates. It is a basic XAML development tool. Expression Blend itself is not free, however, a special version for creating applications for Windows Phone, called Expression Blend 4 for Windows Phone, is available for developers for free. It will be downloaded and installed during the Windows Phone SDK installation if you do not have the full version of Expression Blend on your computer. Read more about Expression Blend 4 on MSDN:

XNA Game Studio 4.0

Windows Phone Emulator

While Windows Phone Emulator does not contain the complete set of applications available on a real device, it provides a powerful framework that allows you to almost completely develop an application in an emulator.

Windows Phone Emulator does not support playing Zune media. The emulator only comes with one built-in Internet Explorer app, but that's Internet Explorer 9 with HTML5 support.

At the same time, the emulator allows you to test calls and sending SMS messages, supports multitouch on monitors with multitouch support, supports simulation of a camera, geolocation services and an accelerometer, and also allows you to take screenshots.

Additional developer tools

Windows Phone Developer Registration Tool

Windows Phone Profiler

The Windows Phone Profiler is available from the Debug menu of Visual Studio with the Windows Phone SDK installed.

Silverlight Toolkit for Windows Phone

Silverlight Toolkit for Windows Phone - A collection of useful Silverlight controls for Windows Phone with design mode support, from the Silverlight development team. All source code, examples and documentation are available. Updated approximately every three months, available at http://silverlight.codeplex.com or via NuGet.

The current release includes controls such as ContextMenu, DatePicker and TimePicker, ToggleSwitch, WrapPanel, and GestureHelper.

Development environment

After installing the Windows Phone SDK Development Kit, the Project Groups for Silverlight for Windows Phone will appear in the New Project dialog in Visual Studio:

and projects for Windows Phone will be added in the XNA Game Studio 4.0 group:

This article series focuses on Windows Phone development with Silverlight, so let's take a closer look at the templates available to an application developer.

After installation, the following Silverlight for Windows Phone application templates are available to the developer:

  • Windows Phone Application
  • Windows Phone Databound Application
  • Windows Phone Class Library
  • Windows Phone Silverlight and XNA Application

Before moving on to app templates, I need to say a few words about Windows Phone and Metro design.

Windows Phone and Metro design

The Windows Phone platform isn't just another mobile platform. It contains not only a technological component, but also a fully developed concept of interface design and user interaction called Metro design or Metro style.

If you are a designer or have a dedicated designer on your team, you can take full advantage of the Expression Blend 4 or Expression Blend for Windows Phone tools that come with the Windows Phone SDK.

What if you are a developer and do not want to do visual design of an application, for example, you are developing a business application and all that is required of it is to match the overall design and style of Windows Phone?

Everything is very simple. First, Silverlight for phone is designed with Metro design in mind, so all built-in controls are in Metro design. Second, by default, apps built from templates supplied with the Windows Phone SDK work, look, and use styles and fonts in accordance with the Metro design.

On the other hand, the styling capabilities of XAML-based controls and applications that Silverlight provides are enough to make your application unique and recognizable while remaining within the Metro style.

Interface Design and User Experience Guidelines for Windows Phone can be found at the following link

All that has been said above applies, of course, to the design of ordinary applications, since the requirements for the design of gaming applications and their interface may differ significantly. At the same time, we should not forget about the general principles of user interaction, embedded in the concept of Windows Phone.

Application templates

First, let's look at three templates that represent the three main styles of a Windows Phone application:

  • Windows Phone Application
  • Windows Phone Pivot Application
  • Windows Phone Panorama Application

Windows Phone Application is an analogue of a simple dialog application that has one main screen through which the main user interaction takes place.

Windows Phone Pivot Application is akin to a bookmarked application, where the title of each bookmark defines the content. A typical use case is that each bookmark represents the same data in general, but in different views and / or with different filtering. For example, calendar, email client and phone settings. The template uses a Pivot control.

Windows Phone Panorama Application - a panorama application in which the user interaction zones are also divided into panels, but they are accessible through horizontal scrolling; the background image is set to the entire panorama at once, it has a common title that scrolls slower than the panels; the content of the adjacent panel on the right is visible when the current one is displayed. For example, hubs in Windows Phone are implemented this way: People, Marketplace, Pictures, Music + Videos, etc. The template uses the Panorama control.

The templates ending in Agent are library templates for performing the corresponding background tasks:

  • Windows Phone Audio Playback Agent
  • Windows Phone Audio Streaming Agent
  • Windows Phone Scheduled Task Agent

Windows Phone Databound Application template - a simple application template with a list view - a detailed view with the implementation of navigation between pages with passing parameters and storing data in the global VeiwModel.

Windows Phone Class Library Template - A class library template for Windows Phone.

A Windows Phone Silverlight and XNA Application template for a Silverlight application that can use XNA to render graphical content.

Building a simple application

In the New Project Visual Studio dialog, select Visual C #, Silverlight for Windows Phone, and a simple Windows Phone Application template and name it ExploringXAMLFeatures.

In the dialog for selecting the target operating system, select Windows Phone OS 7.1

After creating the project, the Visual Studio window will look like this

Consider the project structure in the Solution Explorer window:

File name Appointment
AppManifest.xmlThe manifest file needed to generate the XAP file that packs the application for deployment to the phone.
AssemblyInfo.csAnother configuration file that defines some metadata for the main Assembly of the application.
WMAppManifest.xmlA metadata file that contains various application settings: title, setting the first page, paths to icons, defining the required system capabilities, etc.
App.xamlThis is the application resource file. This is where global resources are located (this will be considered when using styles) or global events (that occur when the application starts). This file is also the entry point for the application.
App.xaml.csCode-behind file for App.xaml. This is where you can handle application-level events and errors, including tombstoning. This concept will be discussed later when multitasking is discussed.
ApplicationIcon.pngA picture that will be the application icon in the phone. This is a really important file as it is the first thing that users will see when using the application.
Background.pngThis picture is used when the application is docked on the phone's start screen. It is essentially a large app icon. It makes sense to make it visually similar to ApplicationIcon.png.
MainPage.xamlThis is part of the selected application template. The name MainPaige is not very apt, but this is what the default project template uses. This page represents the interface that the user sees when the application starts.
MainPage.xaml.csThe MainPage.xaml page code file.
SplashScreenImage.jpgThis picture is displayed during loading + application. You can set your own picture with animation to inform that the application is loading. There is a technique for creating very dynamic XNA download pages, but it goes far beyond the scope of this article series.

XAML files define the interface for an application. They are really just XML files with XAML markup language.

Although this is the simplest project, it contains all the key elements that all other templates and project types contain.

Please note that some of the settings presented as configuration files can be edited in the visual interface for editing application settings.

Adding Controls to the XAML Page

Note that Visual Studio renders both the design and the XAML of the page by default.

If you went to view other solution files, double-click the MainPage.xaml file.

In the XAML of the MainPage.xaml file, inside a Grid named ContentPanel, insert a Button control:

In the design window, the button will appear immediately approximately in the center of the interface. Pay attention to the attribute Name? It is a unique identifier for the item and helps you reference it in your code. Think of this as an ID attribute of the control. Let's now add some action when this button is clicked. There are two ways to bind an event to a Button (or any other control). In XAML, right in the Button definition, you can add the Click attribute and the InteliSense system will automatically ask if we want to generate a new event handler:

You can bind an event handler directly in the code for the Home.xaml.cs page without specifying it in the XAML file:

Public MainPage () (InitializeComponent (); MyButton.Click + = new RoutedEventHandler (MyButton_Click);)

Both methods work. You can use any of them. For simplicity, we will use the XAML method definition here. Now you can write managed code in the MyButton_Click function that will change the interface or call other functions. Let's wrap up our sample application by adding code that will change the text in the TextBlock PageTitle (PageTitle is the Name, so you can refer to it directly in the code) to "hello wp7". To do this, add the following code to the function:

Private void MyButton_Click (object sender, RoutedEventArgs e) (PageTitle.Text = "hello wp7";)

Let's select in the project settings Windows Device Emulator

And launch the application by clicking on the green triangle or the F5 button. After launching the application and clicking on the "Press me" button, the screen should look similar to the screenshot below:

Adding new pages to the project

Only the most basic application consists of one page. We want to learn how to write complex multi-page applications. We can use the Pivot, Panorama templates, we can use the MVVM (Model-View-ViewModel) design pattern, and first we will learn how to add new pages to the project and navigate between them.

In the Solution Explorer window, right-click on the project name, and in the menu that appears, select Add, then New Item, in the dialog box that opens, select Windows Phone Portrait Page and name it SecondPage.xaml:

We now have a blank XAML page, an exact copy of the MainPage.xaml page before we edited it.

To better distinguish between pages, go to the XAML of the SecondPage and edit the TextBlock with the Name PageTitle as shown below:

Navigation between application pages

So, we have two pages in the project, when the application starts, the MainPage.xaml page is displayed. How do I go from MainPage.xaml to SecondPage.xaml now?

Let's try two simple ways to do this.

In the XAML of the MainPage.xaml file, after the Button code you added earlier, add the HyperlinkButton code as shown below:

Top related articles