1. Introduction to Windows 8 Development
Abstract
With Windows 8, Microsoft introduced significant changes to the underlying platform and user interface. These new features include a new start screen experience, Windows stores to purchase apps from a single repository, and a new platform known as Windows Runtime (WinRT).
With Windows 8, Microsoft introduced significant changes to the underlying platform and user interface. These new features include a new start screen experience, Windows stores to purchase apps from a single repository, and a new platform known as Windows Runtime (WinRT).
WinRT provides a new set of APIs and tools to create a new style of touch-first apps that are fast and fluid. These apps are generally called Windows Store Apps.
For the purposes of this book, some of the key things to know about WinRT and Windows Store apps include
Windows 8 Apps runs in Windows X86, x64, and ARM processors.
Windows 8 Apps can either run in full-screen mode or be docked to the side of the screen.
WinRT supports programming languages such ac C, C++, VB.NET, and C#, along with HTML5 and JavaScript.
WinRT APIs are designed to be asynchronous. APIs that take more than 50 ms to run are made asynchronous.
The WPF/Silverlight XAML UI model is exposed to developers.
To ensure stability and security, the Windows Store Apps run within a sandboxed environment.
Finally, the most important thing to know is that there is no direct way to connect to the database servers using data providers in Windows RT.
As this book is more about data access in Windows 8, this chapter provides an overview of the Windows 8 app framework and briefly looks into the development choices, UI data controls, MVVM patterns, and other necessary concepts that will be used in various examples throughout this book. In the later part of this chapter well write our first data-driven Windows 8 App that displays the New York Times Best Sellers list.
Windows App Framework
In Figure , we see the Windows 8 modern-style app framework compared to that of desktop applications, where both share the same Windows core OS services. If we look at the desktop application section, JavaScript and HTML are used to target Internet Explorer, C and C++ are used for Win32 apps, and C# and Visual Basic for .NET and Silverlight. Each of these will have a separate set of APIs. But with Windows 8 Apps, we have one set of APIs that for WinRT whether we use XAML, C#, C/C++, Visual Basic, HTML/CSS, or JavaScript.
Figure 1-1.
Windows App framework
Development Choices
For developing Windows 8 Apps, we can choose either of the two development paths shown in Figure .
Figure 1-2.
Development choices
In the HTML path we will be able to use the traditional Web technologies like HTML5, CSS, and JavaScript. For presentation, you use HTML tags such as div, table, spans, and input, and CSS for styling. For coding, JavaScript can be used. Apart from the HTML controls, Windows Library for JavaScript provides a set of new controls designed for Windows Store Apps. This WinJS library is our path for the WinRT.
If you are a WPF, Silverlight, or Windows Phone developer, then designing the UI and presentation layer using XAML is an ideal fit. Here we will be using C#, Visual Basic, or C++ for coding.
Creating the New York Times Best Sellers App
The New York Times Best Sellers app is a simple Windows 8 App that uses the MVVM pattern to display the New York Times Best Sellers list. Building this app is a starting point to learn to use Visual Studio 2012, the MVVM framework, data binding, data controls, and other necessary concepts to create a data-driven Windows 8 Modern UI app.
Introducing the MVVM Application Framework
Model-View-ViewModel (MVVM) is the most widely used framework in WPF/Silverlight/Windows Phone XAML-based development. Considering MVVM as the central concept of Windows 8, it supports XAML-based development and is ideologically similar to the technologies that use MVVM as the application framework, so it is an ideal choice. This chapter introduces you to the MVVM framework. In later chapters you will learn about some of the most commonly used MVVM frameworks like MVVM Light and Prism.
What Is MVVM?
The MVVM pattern splits the user interface code into three conceptual parts: Model, View, and ViewModel (see Figure ). The concept of the ViewModel is the new, and it controls the Views interactions with the rest of the app.
Model represents actual data or information and holds only the data and not the behavior or service that manipulates the data.
View visually represents the data in the ViewModel by holding a reference to the ViewModel.
ViewModel serves as the glue between the View and the Model by exposing commands, notifiable properties, and observable collections to the View.
Figure 1-3.
The basic relationships of the MVVM framework
Advantages in Using MVVM
These are the some of the advantages of using MVVM over other patterns:
The MVVM pattern is designed specifically for the data binding capabilities that are available in XAML applications, allowing views to be simple presentations that are abstracted from the business logic process, which should not happen at the user interface layer.
Another primary benefit of the MVVM pattern is the unit testability of codebase. The lack of connection between the View and ViewModel helps in writing the unit test against the ViewModel.
MVVM allows developers and UI designers to more easily collaborate when developing their respective parts of the application.
The MVVM pattern is widely used and there are several mature MVVM frameworks like Caliburn Micro and MVVMLight that provide all the base template code out of the way, of course, but they also can add advanced binding, behaviors, actions, and composition features.
Setting Up the Development Environment
Download the developer tools from http://dev.windows.com . The developer tool includes the Windows 8 Software Development Kit, a blend of Visual Studio and project templates. Microsoft Visual Studio for Windows 8 is our integrated development environment (IDE) to build Windows 8 Apps and this version runs only on Windows 8.
Optionally, Microsoft Visual Studio 2012 can also be used. The full version has advanced debugging tool support, multi-unit testing framework and refactoring support, code analysis, profiling, and support for connecting to Team Foundation Server.