How to Build Windows 8 Applications

How to Build Windows 8 Applications

Develop mobile, touch-based apps in less time

Windows 8 is the biggest transition for the Windows brand since 1995. It attempts to meet new challenges: the advent of touch as a primary interaction pattern, the growing threat of malware, and the need for extreme mobility in applications. For more information on Windows 8 development, see "How to Use Windows 8 Live Tiles in an Application" and "How to Work with Local Notifications in Windows 8-Style Apps."

Developers will be able to carry forward some of their existing knowledge into the new Windows 8 development world: You'll still be using Visual Studio, and if you have XAML expertise, you'll be able to carry that forward. C# and Visual Basic are both at your disposal for Windows 8 development. However, you'll also need a number of new skills. Some of these skills are purely technical, such as learning how to make your apps work with Windows 8 state management. You'll also need some softer skills: You must become fluent with touch for user interaction and become familiar with the user experience (UX) guidelines for Windows 8. You'll also have to learn how to work with the Windows Store for deploying your apps.

To help you make the shift, I'll run through the major new areas where you need to invest to prepare yourself to build apps for Windows 8. Most of them don't take huge amounts of time, but the list is longer than you might expect.

Learn Windows 8 Touch Conventions

Your first step is obvious. Get a touch-based Windows 8 machine, and begin using it routinely. Gestures such as swipes and tap/hold need to become second nature to you. Experience with a touch-based smartphone or tablet will shorten your learning period -- but it won't eliminate it.

Windows 8 has its own conventions for touch, and you'll need to be fluent with them. You'll need to learn about charms, app bars, and navigation bars. Figure 1 shows the basics, with a diagrammatic screen indicating those three elements. Each element is brought into view by swiping from a particular side of the screen: right for charms, bottom for app bar, and top for navigation bar.

Figure 1: The Major Elements that Swipe in from the Sides of a Windows 8 App
Figure 1: The Major Elements that Swipe in from the Sides of a Windows 8 App

You also need to know your options. Charms are always present; they're part of the OS. But you get to choose whether to use an app bar, a navigation bar, or both. A lot of applications use just an app bar, which contains operations such as Save. But Internet Explorer, for example, uses only a navigation bar that navigates among browser tabs. Your app might need a similar navigation pattern.

Learn XAML Essentials

If you've been developing in Silverlight or Windows Presentation Foundation (WPF), you're in good shape to start using XAML in Windows 8. If you've done Windows Phone 7 development, you're even better prepared. However, if you lack such a background, then learning the raw essentials of XAML is probably your biggest hurdle for building XAML apps in Windows 8. You've got some major areas of expertise to acquire, including these:

  • XAML syntax
  • XAML layout and composition: how elements are arranged and combined
  • data binding
  • data templating
  • styling and control templates

You can use existing resources, such as books and training videos, to become familiar with these XAML concepts. The general concepts, and quite a bit of the precise syntax, are the same in Silverlight/WPF as in Windows 8.

Understand XAML Differences for Windows 8

There are also many differences in the details of using XAML in Windows 8. Certain controls and elements found in WPF and Silverlight are missing, for example, and Windows 8 adds some new elements of its own. For example, the new GridView and FlipView controls integrate much of the touch navigation your users need to navigate a set of data items. You'll use ListBox less than in earlier XAML platforms, with GridView, FlipView, and ListView tending to fit better into a Windows 8 UX.

You'll have to contend with API differences as well. There are missing features, such as data binding for Style values. The syntax for setting an XML namespace in XAML has changed: Instead of using "clr-namespace" to prefix an assembly name, the prefix is now "using." These are just two examples of numerous minor differences.

Some API changes mean you'll need code modifications to bring over functionality from earlier XAML efforts. For example, the method signature has changed in the widely used IValueConverter interface.

Understand App Suspension and State Management

If you've done Windows Phone development, you'll be generally familiar with the pattern used to suspend and resume apps in Windows 8. The important factors to note are that your app might not remain in memory indefinitely; that's under control of the OS. That means there are some very explicit guidelines on functionality such as background processing.

As an app developer, your first responsibility in this area is to understand the events that occur during app navigation and what you typically need to do for those events. The most typical actions in the events are saving session state and restoring session state.

Session state in Windows 8 is conceptually like ViewState in ASP.NET pages, but session state resides in local memory, so it can be much richer. Session state consists of any information that the app doesn't want to lose when it's suspended. The two most important session-state events are

  • OnLaunched, which fires when the application is first started but also fires whenever the app is brought back into view for actions such as loading a file. If necessary, this is where you need to reload session state. You also need to navigate to the appropriate view in this event.
  • OnSuspending, which fires when execution is being suspended. This is where you typically save application state.

Two of the templates available in Visual Studio have typical sample code for handling these events and managing state. Let's take a look at the available templates.

The templates for XAML apps in Visual Studio. You get some serious help in constructing your app from the new application templates that come with Visual Studio 2012. For Windows 8-style apps, there are three built-in templates: the Blank App template, the Grid App template, and the Split App template.

The Blank App template isn't a good starting point for learning how to construct Windows 8 apps. Instead, you should start with the other templates, which include a lot of built-in functionality that a Windows 8 app needs. That doesn't mean the Blank App template is useless. Besides furnishing a way to quickly check features or APIs, it's also a good starting point for an app once you've mastered the requirements of Windows 8, especially if your app doesn't fit the interaction patterns supported by the other two templates. But you'll learn how a Windows 8 app is supposed to work faster by using the other templates.

Once you've created an app using the Grid App or Split App template, you'll have a functional program with some sample data. Figure 2 shows a typical starting screen for an application based on the Grid App template.

Figure 2: Initial Screen for an Application Based on the Grid App Template
Figure 2: Initial Screen for an Application Based on the Grid App Template

The solution will also include a number of items that contain quite a bit of standard functionality. Many of those items are in the Common folder. The StandardStyles.xaml item in the Common folder has many XAML resources that will likely be used throughout the application. Some of them you might want to leave untouched, such as brushes. Others, such as data templates, need to be customized to your app needs.

Also in the Common folder are a number of base classes that are used to create views in your app. These base classes include a lot of functionality that Windows 8 needs, so you don't have to create this functionality or replicate it in your own views. For example, the built-in page base classes know how to handle a "snapped" view, which we'll discuss shortly.

Getting the template to work with your own data will require you to take several steps. You'll need to create your own data model, provide a service layer to access it, and replace the built-in sample data with your model. The details of how to perform these tasks are too lengthy for this article; suffice it to say, you can expect to spend a few hours becoming familiar with where data is handled in the logic generated by the Grid App and Split App templates.

Become Familiar with UI/UX Guidelines

Besides giving you a sample of Window 8 application internals, the built-in app templates also demonstrate a basic UX for Windows 8 apps. It's just a starting point, though; becoming conversant with the entire set of guidelines for Windows 8 UXs will take you a while. You can find a launch page for the complete set of guidelines on the Dev Center's Designing UX for apps page, and I advise you to study those carefully.

Here, though, are a few of the main concepts that probably differ significantly from those you've used in prior applications.

  • Interaction with the OS is different. We've already covered some touch guidelines and summarized the new visual elements in Figure 1. OS interaction also includes "contracts," which are important enough to merit their own discussion in this article (see the next section).
  • Windows 8 apps are "chromeless." You'll see no overlapping windows, no sizable borders, no close buttons, and no minimize buttons. The OS presents a clean surface that usually focuses on one application at a time.
  • Multiple applications are shown only via a "snapped" view, with a limit of two apps at a time. In a snapped view, one app gets a reduced slice of the screen that's 320 pixels wide. The rest of the screen, which is significantly bigger, hosts the other app. Your app is required to support a snapped view.
  • Your app shouldn't have a Close button or other similar functionality.
  • You should to stick to the standard fonts recommended for apps. The most commonly used font in Windows 8 apps is Segoe, and it's certainly nice enough that there's no reason to change it for line of business (LOB) applications. Other fonts are available for areas with a lot of content to read or edit.
  • You need to try to be consistent with the standard sizes for individual items in your app. The built-in templates will give you a push in the right direction by setting up standard data templates with those sizes.

This list is just a starting point for UX guidelines. You'll need to become familiar with the entire set. Besides promoting consistency, some of the UX guidelines are required for your app to be certified in the Windows Store, as I'll explain shortly.

Get to Know Contracts

A major innovation in Windows 8 is the use of contracts to standardize certain types of interaction among applications and between apps and the OS. This is an area of particular interest to developers because you'll need to write code that implements your app's interaction via contracts. The two main contracts you need to be concerned about when you begin are Search and Share.

The Search contract allows your app to participate in a search requested by a user via the Search charm in the charms panel that slides out from the right. The OS automatically carries out certain search operations, including finding applications (desktop applications as well as others) that satisfy a search string. However, in addition to yielding results of its own, the OS gives any running applications the opportunity to contribute search results.

The Share contract is conceptually similar and is also associated with a charm. However, the Share contract is more open ended: It can be used for apps to talk to each other and exchange information.

Get Comfortable with the Windows Store

I mentioned early in the article that fighting malware was a leading design objective for Windows 8. Malware costs billions of dollars a year and is growing in cost as malware authors target systems to gather credentials of financial accounts. The easy deployment channels in earlier versions of Windows were designed for quick and flexible deployment of applications. In an online world, malware authors learned to subvert those channels.

Enter the Windows Store. It's the primary broad-based deployment mechanism for Windows 8-style apps. Application authors must go through a detailed process to get their apps in the store, and apps are further vetted by the Windows Store before being made generally available. This process puts significant barriers in place that malware authors must surmount.

But if we've learned anything, we know that malware authors will slither in through any crack. Some malware might make it into the Windows Store. However, there are other layers of protection. One is the ability of the store to keep malware from spreading. Because the app is deployed from a central point not under control of the malware authors, a single report of malware can start the process of removing the malware from the store, halting its spread.

Finally, the security model in Windows 8 has various restrictions on what an app can do, so it prevents some of the actions malware authors would most like to carry out. Together, this combination should change the economics of malware to make it quite rare in the world of Windows 8 apps.

Getting an App in the Windows Store

For developers, the Windows Store certainly involves some extra work. However, in addition to fighting malware, another benefit of the Windows Store is that it can help you to more easily monetize an app. The Windows Store can collect a purchase price, extract a fee, then deposit the remaining balance in an account for a developer or organization. These benefits make it worth your while to jump through a few hoops to use the Windows Store. Here are the most important ones:

  • packaging apps for the Windows Store
  • validating apps with the Windows App Certification Kit
  • getting an account at the Windows Store
  • uploading apps to the Windows Store and supplying the information needed for users to find and acquire the app

Many of the operations you'll need are on a special menu in Visual Studio 2012, which contains options for packaging apps, validating apps, and working with the Windows Store. The menu is accessed on the Visual Studio menu via Project, Store, as shown in Figure 3.

Figure 3: The Visual Studio 2012 Menu for Packaging Apps and Working with the Windows Store
Figure 3: The Visual Studio 2012 Menu for Packaging Apps and Working with the Windows Store

The third option on the menu is for acquiring a developer license. However, you probably won't need to select this option right away because you'll be offered an opportunity to get a developer license the first time you open Visual Studio 2012.

To package a Windows 8-style app, you should select Create App Packages. This starts a process that yields a package for your application. Such a package is needed for two reasons: validating the app and uploading it to the store.

After a package is created, a status dialog box will display. This dialog box also has a button labeled Start Windows App Certification Kit to begin the validation process for the app.

The Windows App Certification Kit is part of the Windows 8 SDK, which is installed along with Visual Studio 2012. Besides validating an app with the button mentioned earlier, you can also start up the validation program manually. The program is named appcertui.exe. Depending on whether you have 32-bit or 64-bit Windows, the program will likely reside in either C:\Program Files\Windows Kits\8.0\App Certification Kit or C:\Program Files (x86)\Windows Kits\8.0\App Certification Kit. It's best to get a cup of coffee or find something to do while the validation is in process, because you need to avoid interacting with the app, and it will be popping up a few times. At the end of the process, a dialog will tell you if the app passed or failed validation.

Everything else concerning the Windows Store requires you to get an account in the store. There are individual accounts and business accounts. Business accounts are validated more closely by the store, but they also allow your app to have additional functionality such as allowing the use of Windows credentials to access a corporate intranet.

Getting an account is a multi-step process, but it isn't difficult. The menu option Open Developer Account will get you started. Make sure you choose your "publisher display name" carefully. The store will use this name as the app publisher for all your apps. It must be unique, and you must have permission to use the name you enter.

After you acquired an account, the two main operations you'll need to perform are reserving an app name and uploading an app. The menu options Reserve App Name and Upload App Packages correspond to those actions.

You can reserve an app name at any time, even before beginning work on an app. A name is reserved for a year, so if you have a clever name for your app, go ahead and reserve it to ensure you get it. Upload App Packages links to the Windows Store screen, where you carry out various steps to make your app available in the store. In addition to the final step of uploading the package, you must complete other steps such as supplying information about your app that will be needed for the app catalog.

Side-loading. For LOB apps, you have an alternative to using the Windows Store. You can use a process called "side-loading" for an app. There are several restrictions; otherwise, such a mechanism would open up another malware hole.

First, your app must be signed. You can use the temporary certificate generated for your app by Visual Studio—which is acceptable during testing. However, for proper security, your organization should sign the production version with its own certificate. Your IT staff should be familiar with the ins and outs of certificates.

There are a couple of other steps required, depending on the exact versions of Windows 8 you'll be supporting on client machines. You can find detailed information about side-loading in the blog posts "Deploying Metro style apps to businesses," "How to Add and Remove Apps," and "Side-loading on Windows 8."

Moving Forward

You might be feeling a bit overwhelmed at this point, considering the long list of things you must learn to develop Windows 8-style apps. It's not as bad as it looks at first glance, though. Some of those checklist items are one-time tasks, and others—such as reserving an app name—are quite straightforward.

Your major time investment will be in understanding how to program Windows 8 apps in XAML and how to satisfy the conventions of Windows 8 for navigation, suspension, and UX. The payoff will be a platform for developing mobile, touch-based apps with more capability and in less time than other competing platforms. Take some time to digest the new information, then get started!

Learn More About Building Windows 8 Applications

Billy Hollis is a developer and designer who offers consulting and training in both XAML and general design concepts. He has written several books, and he is a contributing author for the upcoming Professional Visual Basic 2012 (Wrox Press).

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.