Chapter 1. Windows 8: A Quick Tour

When the Windows 8 design language was first announced at MIX 2010, I knew Microsoft was on to something. I really enjoyed the simple use of typography and a focus on content. At the Build conference in September 2011, Microsoft announced its plans to expand the Windows 8 design language to other products, including its flagship product, Microsoft Windows. This release marks a convergence of the latest versions of Windows, Windows Phone, and Xbox where all three use Windows 8 and promote the concept with a trifecta of opportunities that will hopefully complement one another and grow consumer awareness about the collective suite of offerings.

Windows 8 apps are designed primarily for touch interaction, and Windows 8 has been written with this in mind. Microsoft is calling this the reimagining of Windows. Everything from the desktop to the start menu has been redesigned and optimized for touch. The Windows Runtime (WinRT), a new application model for running Windows 8 apps, provides access to the new features of the Operating System (OS) and the native hardware capabilities that are available on modern computers, tablets, and slates. This chapter focuses on what it means to reimagine Windows and what’s available to help developers reimagine their apps as well.

A User Interface for Touch

In line with other Windows 8–focused technologies like the Windows Phone and Xbox, the main interface for Windows is a vibrant start screen where tiles are used to launch apps. They are big and easily activated on touch devices while providing content that is up-to-date and visible even when flicked across the screen. Unlike desktop apps, Windows 8 apps don’t have borders or windows, which are difficult to interact with using touch. Instead they are all full screen, enabling an immersive experience where your apps contain only relevant content. When an app launches in Windows 8, you use specific gestures—swiping in from the bezel on the right or bottom—to activate new touch-based menus. The system menu, or start bar, in conjunction with the Windows Runtime, provides a new model for connecting apps. Once an app is running, you can change settings, search, and share content with other apps without having to leave the full screen experience.

Start Screen

The new Start Screen that powers Windows 8 apps in Windows

Figure 1-1. The new Start Screen that powers Windows 8 apps in Windows

The new Windows 8 start screen, shown in Figure 1-1, provides a fast and fluid way to interact with all your important content. From checking email or the latest news, glancing at the weather or your stocks, checking in with your friends on various social networks, or just listening to music, the start screen keeps you updated on your life. This means no bouncing between apps and the home screen just to check statuses.

Tiles make up the start screen with their bright colors and clean text. They can be organized into groups and personalized for each user. Simply tapping a tile launches the app in a full screen view. Apps can have either small or wide tiles in a number of different styles, providing clean and exciting animation. In addition to the primary application tile, apps can define additional tiles. For example, the weather app might show its tile with information from your hometown in New York. Before going on vacation, you can add a secondary tile for your destination of London. The secondary tile can provide live information about the weather in London, and when you tap the tile, the weather app will launch directly into a detailed view of London’s weather.

By default, start screen settings are stored in the cloud, which allows the layout of your tiles to be consistent across all devices. Using the pinch gesture for zooming out, you can get a broad glance at your start screen and see a list of all the application groups.

With this new user interface come many new features and ways to interact with Windows. In conjunction with the new start screen comes a brand new start bar, which allows users to get back to the start screen or communicate with other components of Windows or the other apps installed on the system.

Start Bar

The start button has been a keystone of Windows for many releases. It has undergone numerous changes, but this one is by far the most drastic: Microsoft has replaced the start button with a Start Bar, which is the hub of inter-app connectivity. In addition to the typical Windows logo that will return you to the start screen, the Start Bar contains charms. Regardless of which app is running, you can use charms to access common features such as searching and modifying settings. You can also use the Share and Devices charms to quickly send content to other apps or hardware such as your printer. To display the Start Bar, simply swipe your finger in from the right side of the screen and it will slide into place.

With the Start Bar visible, you will see an overlay with system status information on the lower-left side. It displays notifications, network and battery monitors, and the current date and time (see Figure 1-2). The Start Bar, on the right side, contains the Windows logo and four charms.

Note

When using a mouse, take advantage of the screen’s corner features. Move your mouse to the top right corner and it the Start Bar will appear. If you prefer keyboard shortcuts: Windows key + C will show the Start Bar.

New Windows Start Bar slides in from the right side

Figure 1-2. New Windows Start Bar slides in from the right side

Each of these charms are as follows:

Search

Windows has merged the All Programs list and the File System search into a common UI for searching everything on your computer (see Figure 1-3). The same interface for displaying apps is used to provide search throughout the Windows experience. You can search for apps, files, settings, and any information provided by your installed apps.

Note

When using a keyboard, you can just start typing on the start screen to search for an app. If you are in an app, you can click the Windows key and then start typing.

New Windows Search offers a replacement view for All Programs

Figure 1-3. New Windows Search offers a replacement view for All Programs

Share

Share provides a way to send data to other applications without having to leave the app. Early samples treat this as an alternative to traditional copy-and-paste methods; examples include posting to Facebook, Twitter, or sending email, but the possibilities are endless.

Devices

Devices allows apps to communicate with the computer’s hardware. The initial examples include printing, projecting, and sending content to your Xbox, other device, and/or USB hard drives. Device manufacturers can communicate with apps in ways that are relevant to a particular device. Screens for this section will typically be developed by device manufacturers. For example, your printer will have specific screens for its use.

Settings

Settings is split into two sections: system settings and app settings. System settings contain quick access to networking, volume, screen, notifications, power, and keyboard. App settings depend on the app and developers should determine what settings are relevant to their apps.

Windows Programming Reimagined

The Win32 APIs have been a core component to native Windows programming for over 15 years. In addition to all the changes to Windows, Microsoft is reimagining the way in which programs, or apps, are written. Windows 8 apps can be written using the following languages:

  • JavaScript and HTML5/CSS3

  • C# and XAML

  • VB.NET and XAML

  • C++ and XAML

  • C++ with DirectX

  • Hybrid

All of the languages above are designed to be first class citizens. This means that no matter what language you choose, you will have equivalent capabilities. At this point, the decision of which language to use is strongly guided by the preferences of the team. Regardless of the choice you make, all Windows 8 apps communicate with the new Native Application Programming Interface (API) called the Windows Runtime, or just WinRT for short.

A New Native APIJ: The Windows Runtime

Windows 8 apps are based on a new application model that has been completely rewritten from the ground up. While the Win32 APIs were written for C, WinRT APIs written in C++ and designed to be object oriented. This gives the APIs the flexibility to be used by multiple languages. Everything that is needed to host an application and communicate with the operating system has been updated or rewritten in native C++ and is exposed out via an API Metadata format (.winmd file).

This consistent framework allows the API to be optimized for performance. File access can be centralized and made consistent across all languages. User interface components can be hardware accelerated and common animations can become easily accessible. Resource management is handled at a higher level and currently running applications can be confident that they will be given additional resources if the system experiences pressure. In total, this gives users a better experience.

Language Support

Between the different languages and the new WinRT APIs is a layer called the projection layer. This layer maintains the proxies and handles the activation of WinRT objects. For C# developers, this means no more P/Invoke. Write the C# code just like regular code. While WinRT is designed for use with JavaScript, C#, Visual Basic, and C++, this book will focus on C#. The techniques are often the same and the syntax is surprisingly similar considering they are different languages.

JavaScript

Windows 8 apps leverage the Internet Explorer WebHost, to render HTML5/CSS3, and the Chakra JavaScript engine to execute native web apps. These apps are as flexible as existing web apps, but they can perform tasks previously available only to desktop applications—tasks like using the camera to take a picture, accessing the accelerometer to determine the tilt of a device during game play, or reading and writing to a file on the local filesystem. In addition, JavaScript apps can communicate with other apps on the OS, as a source or a target of information, and provide interactive tiles and secondary tiles.

C# and Visual Basic

Existing WPF or Silverlight developers might wonder why the name changed to C# or Visual Basic and XAML and the answer comes from the addition of C++ and XAML. If you wanted to expose all of XAML to C++ as a UI technology, it wouldn’t make much sense to spin up the CLR just to parse and render some XAML only to revert back to C++ for the remainder of your code execution. The only logical answer is to push XAML down further in the stack and expose it out through the same projection layer that is used for other Windows Runtime objects. This means that the XAML consumed from these Windows 8 apps is now written in C++. Although many of the XAML controls and binding techniques remain, there are slight differences, and it is a complete rewrite in a completely new language after all.

For developers who are familiar with .NET, you’ll find many of the APIs and libraries will still be available. Microsoft has created a new profile called the .NET Profile for Windows Windows 8 apps. Like the .NET Client profile, this is a subset of the full .NET Framework that is specific to Windows 8 apps. In the process, they’ve removed duplicate and legacy code; optimized APIs for multiple core machines and asynchronous development; and hardware accelerated the UI layer. There may be new APIs to learn on the WinRT side, but .NET developers should find the developer experience extremely familiar.

You can think of this change as if Microsoft took Silverlight or WPF and cut it in half. The XAML UI and application hosting controls were moved into the Windows Runtime with many brand new native Windows features. The remainder of the .NET components have been moved to this new .NET Profile for Windows Windows 8 apps.

C++

Microsoft has made changes to C++ in the past to make it compatible with managed languages, and they continue to do so with WinRT. There were similar challenges in order to cooperate with WinRT, but unlike the managed C++, developers need a way to transition between native and managed C++. Windows 8 comes with a new C++ compiler switch (/cx) that enables the C++ Compiler Extensions. This exposes typical managed concepts, such as reference objects, partial classes, and generics, but allows easy portability between their native counterparts.

Note

The WinRT libraries themselves are written through the same C++ extensions made available to C++ developers. Objects that are projected out to other languages use a managed wrapper object, which points to the same memory as the native objects.

Hosted Application Model

Each Windows 8 app is loaded into a new application host. The most important responsibility is resource management. The way Windows ensures that the current app has the necessary resources available is by closing down other apps when needed.

The two main resources that apps typically consume are CPU cycles and memory. These shutdowns are handled separately. First to be taken care of are the CPU cycles; shortly after an app has left the foreground, it receives an event signaling itself to deactivate. This is the last chance to save state or consume the CPU, and this must be handled in a timely fashion. This is called tombstoning and from here the app is in a suspended state. The second step occurs when your system is low on memory. In this case, Windows will terminate the app without notification to free up memory. Developers can gain some startup performance if they realize that their app is not always terminated and they retain items in a cache. More information on tombstoning can be found in Chapter 3.

Single File Deployment

In the process of reimagining Windows, the application model, and the application programming interfaces (APIs), Microsoft overhauled the deployment process. This is the first time that Microsoft has allowed native apps to be installed from a single file. This file, or deployment package, is an .appx (pronounced App-X) file.

This new deployment process includes incremental updates. They support side-by-side installs of different versions for multiple users. Each application package is digitally signed with a certificate and hashes are created and verified for each app before execution. More information about .appx packages can be found in Chapter 5.

Windows Store

Getting your app to market and in front of Windows’ large install base is simple with the integrated Windows Store. In order to have apps published in the Windows Store, developers will have to submit apps for certification. Certification will verify code for a number of different conditions, such as invalid access to protected APIs, the use of proper capabilities, and proper handling of exceptions. More information about the Windows Store can be found in Chapter 5.

Inside Windows 8 Apps

The Windows Runtime provides a simple model for building apps of any type or design. However, in order to make a cohesive experience for all users, Microsoft is promoting a few design concepts that you should follow when building apps. These concepts include designing with typography, placing the back button in a consistent location, using the Application Bar, and providing elegant animation. Windows 8 apps come with built-in support libraries and controls for these, so implementation is simplified.

Application Bar

With full screen apps and the lack of chrome on the windows, interfaces lose menu bars. These are the links you typically see at the top that say File, Tools, Help, etc. Windows 8 apps have included a new Application Bar that is meant to provide application-specific buttons. When the user swipes a finger up from the bottom bezel, it slides into place just like the Start Bar, but from the bottom instead (see Figure 1-4).

Note

To activate the application bar with a mouse, just right-click or click Windows key + Z on the keyboard.

Weather app sample in Windows 8 showing the Application Bar

Figure 1-4. Weather app sample in Windows 8 showing the Application Bar

Application Bars are optional and completely customizable. Many apps are built so the Application Bar varies based on the context of the current page. The checklist for designing Application Bars is available at http://msdn.microsoft.com/en-us/library/windows/apps/hh465302(v=VS.85).aspx; it recommends right-aligning commands that vary in the app bar and left-aligning all the buttons that are consistent throughout the application.

Warning

Application settings do not belong on the Application Bar and should leverage the Settings charm on the Start Bar. More information about the Settings charm will be described later in Chapter 3.

Semantic Zoom

Anyone who has used a touch device is familiar with the pinch and stretch gestures used for zooming. This gesture has typically been used for zooming images, maps, or applications that have a functional requirement for zooming. Microsoft is trying to prove that almost every app can benefit from this semantic zoom. For example, if you have a list with hundreds of items, you can pinch your fingers on the screen, change the icon size, and get a view that provides more items than a standard list. Semantic zoom must be something that you decide to incorporate into your app, since it does not work by default. The sample app from the Build conference provides a great example: by simply pinching on the schedule of sessions you can change the list from a full view to a high level glance of all days (see Figure 1-5 and Figure 1-6).

Sample app from the Build conference in full view

Figure 1-5. Sample app from the Build conference in full view

Sample app from the Build conference after pinching to zoom out

Figure 1-6. Sample app from the Build conference after pinching to zoom out

The Windows Runtime provides built-in controls for SemanticZoom. This control has two zoom levels a ZoomedInView and a ZoomedOutView. To implement the control you provide a custom GridView or ListView for each view.

Animation

In order to build rich user experiences in your Windows 8 apps, consider the proper use of animation. Regardless of the language used, traditional forms of animation are still available, such as DOM manipulation in JavaScript, or storyboards in XAML. In addition, Windows 8 apps come with support for some common animations and transition.

In XAML-based applications, you can use ThemeTransitions. These are provided by the Windows Runtime and as with any XAML control, you can create your own transitions or use one of the built in ones listed in Table 1-1.

Table 1-1. A list of WinRT XAML animations from Windows.UI.Xaml.Media.Animation

MethodsDescriptions

EntranceThemeTransition

Provides a subtle animation to slide content into place as it enters the UI

RepositionThemeTransition

Animates any change to an item’s position

AddDeleteThemeTransition

Provides animation for when items get added/removed to a parent panel

ContentThemeTransition

Animates changes to the Content property of an element

ReorderThemeTransition

Animates the changes to a panel in response to filtering and sorting children

For a full list of XAML animations see http://msdn.microsoft.com/en-us/library/windows/apps/br243232.aspx.

Animations will not be covered in depth in this book. For more information about animation using XAML you can find separate documentation at http://msdn.microsoft.com/en-us/library/windows/apps/hh452703.aspx.

Outside Your App

Almost every application needs to communicate with the Internet or devices in some fashion. Windows also contains numerous features that any compelling app will likely leverage. While the previous sections focused on the new features of Windows and the application development platform, this section focuses on the new features specific to Windows 8 apps and how they communicate with functionality outside the app.

The tiles on the new start screen can be updated periodically to provide important details regarding your app. Apps can send and receive information from various open contracts allowing them to get content from a web of other apps on the users’ system that are unknown to developers at design time. Implementing these features appropriately adds to the users’ experience when they use your app, and creates a better web of collective apps for users.

Tiles

Every Windows 8 app comes with a primary tile. Developers must provide an image for every application to be used as the default tile. This tile is displayed until the application is launched and an update is sent. The default tile has to be a static image (150x150 for square tiles, and 310x150 for wide tiles). Once an update is sent, the tile becomes a Live Tile. Depending on the app, it may highlight an upcoming appointment, the weather in the neighborhood, or the latest sports scores for a favorite team. These apps are providing information even when they are not active.

In addition to a primary tile, you can create multiple secondary tiles for your app. The difference is that secondary tiles can link to a specific page or section in your app, a process called “deep linking.”

Pickers

Due to the multitude of viruses, malicious software, and the like in the wild, Microsoft has tried to thwart these attempts by disabling raw access to the filesystem. WinRT provides a feature called pickers. Pickers come in a variety of forms, such as FilePickers, FolderPickers, and ContactPickers. They provide the functionality of a typical file dialog box, except that they also can expose content from third party apps. If your app has data relevant to these pickers, you can provide a contract that allows your app to provide data to any other app that uses the same file picker. Figure 1-7 shows a file picker of images. Notice the Socialite app (Socialite is a Facebook demo) listed in the menu. This allows you to pick images from your photos that were previously uploaded to Facebook.

File Picker showing a drop-down menu with custom apps (Socialite)

Figure 1-7. File Picker showing a drop-down menu with custom apps (Socialite)

Charms

A big challenge in current Windows development is sharing content between applications. Pickers do a lot to help this, but let’s say you wanted to share a link from a news article with all of your Twitter followers. This was possible in Windows 7, but it caused an abrupt context switch. You copied the link into your clipboard, started the Twitter client, switched applications, pasted the link, shared the content, and then you could switch back to your previous task. In Windows 8, you can simply activate the start bar, choose the Share charm, select a Twitter client, and click share without ever having to leave the application.

Apps can define capabilities that allow them to be both sources and targets for charms. More information on charms can be found in Chapter 4.

Sensors and Devices

Windows 8 is packaged with support for more sensors and devices because of new devices like tablets and mobile computing. The sample tablet from the Build conference has a forward and rear facing camera, an accelerometer, a GPS, and even a near field communication card. As a developer, you have access to use them for any application.

The Windows Runtime includes APIs for communicating with all kinds of hardware. Some of these devices may be relevant only to tablets. Regardless, these APIs make communication with these devices easier than ever before. They provide consistency and access to raw, native features so complex algorithms and streaming servers are not required.

More information about sensors and devices can be found in Chapter 4.

Summary

You have been given a glimpse of what is in store for you as you begin to develop for Windows 8. This is one of the biggest releases for Microsoft in some time, with enhancements to ensure a safe and optimal experience for the user. I hope this book will show you how writing Windows 8 apps can be a pleasurable experience for developers as well. Maybe your app will be the next featured app on the Windows Store, with downloads beyond your expectations.

Get Getting Started with Windows 8 Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.