Creating a UWP app

One of Microsoft's goals for UWP apps is to truly make them universal so that they run on any system based on the core Windows 10 technology—not only traditional desktop computers, but devices ranging from Raspberry Pi, to Xbox One, to Microsoft's new HoloLens.

In this recipe, we will begin by creating a brand new UWP app to see how the process differs from Windows 8.X app creation, and the new capabilities made available to us.

Getting ready

Windows 10 is required for this recipe. Visual Studio Community will be used to provide the example screenshots, but of course, a premium edition or VS Express for Windows 10 would also be suitable.

How to do it...

The types of app templates available has changed with VS2015 and Windows 10. Let's begin by creating a Blank App. For our example, we will use C#:

  1. From Visual Studio's File menu, navigate to New | Project…
  2. A dialog showing the available project templates will appear. From the Installed templates category, navigate to the Visual C# | Windows | Universal | Blank App template:
  3. You may leave the default project name or change it to one of your choosing, and click on OK to create the app.
  4. If you chose to use a source control system, make your selection now. (We will cover this in greater detail in a later chapter.)
  5. The newly created project will appear in Solution Explorer, and App.xaml.cs will open in the document area.
  6. Press F5 to run the application in the Debug mode. Visual Studio will package and launch the app for you. As you might expect, we are presented with a blank app window (marked by 1 in the next screenshot). However, note that in VS2015, executing an app under debugging mode also runs Diagnostic Tools (marked by the 2):
  7. When you have finished exploring the app, you can use Shift + F5 as a direct command to stop debugging. However, you may find that the best approach is to use Alt + Tab to switch back to Visual Studio, and stop debugging from there.

How it works…

Those familiar with app development under Windows 8.X and VS2013 are no doubt wondering what happened to the usual templates. Those of you new to UWP app creation are wondering why the app is blank. In VS2015, the various types of templates with predefined GUI elements have been removed, in favor of some key starting points to which different layouts and GUI elements can be added. Different templates are available, based on the language you wish to develop with.

There's more…

Let's take a look at the available project templates, and what they can provide us. JavaScript developers will find only the Blank App template provided to them, while C#, Visual Basic, and C++ developers find a larger selection to choose from.

Choosing the right project type…

There are several Universal Windows app templates available. We are going to provide a brief overview so that you can decide what template would make a good starting point for your next project.

Blank App

The Blank App template is exactly what we have seen in this recipe—an empty shell ready for your customizations. It is available for JavaScript, C#, C++, and Visual Basic.

Class Library

The Class Library project creates a DLL for use with UWP apps, which is automatically set to use the .NET Framework. This promotes code reuse, and allows you to separate business logic from app-specific code. This is available for C# and Visual Basic.

Windows Runtime Component

The Windows Runtime Component is a project template for creating code in one language that can be shared or consumed in other languages. C#/VB/C++ can all create and consume these components for UWP apps. JavaScript can only consume these components. Components let you take advantage of the features of each language, and then combine them into a single application.

For example, code requiring high performance can be written into a C++ component, and consumed by a JavaScript app. Or perhaps you have existing business logic written in Visual Basic, but want to use it in a brand new C++ app written to take advantage of the UWP features. These types of scenarios are facilitated with this project type, which uses exposed Windows Metadata (.winmd file) information to facilitate this interoperability. This is available for C#, C++, and Visual Basic.

Unit Test App

The Unit Test App project template creates a Unit Test Framework or a test assembly based on CppUnit for unit testing your code. It is available for C#, C++, and Visual Basic.

Coded UI Test Project (Windows Phone)

The Coded UI Test Project (Windows Phone) template allows you to test your Windows Phone-targeted app via the GUI, rather than underneath the hood as in the Unit Test App. It is available for C# and Visual Basic.

Coded UI Test Project (Windows)

The Coded UI Test Project (Windows) template allows you to test your app via the GUI, rather than underneath the hood as in the Unit Test App. Unlike the preceding template, this is not Windows Phone-specific. This is available for C# and Visual Basic.

C++ specific UWP templates

Developers using C++ have several unique UWP templates available for their use. They focus on DirectX, but also include some key infrastructure components:

  • DirextX11 App and DirectX 12 App: Used to create a new project that uses the indicated DirectX features. Perfect for games or applications requiring high-performance graphics.
  • DirectX11 and XAML App: A template that provides DirectX 11 support along with XAML. This allows XAML controls to be used for controlling your app, while using DirectX to provide rendering.
  • DLL: Lets you write a DLL using C++, and then makes it available to other UWP apps.
  • Static Library: Similar to a DLL, with the notable exception that this is for static linking. Can be consumed by other UWP-based apps.

Tip

Veterans of Windows 8.X app development will notice that Portable Class Libraries are not part of the UWP, but those templates remain available for use with other projects.

Language interoperability

UWP apps written in JavaScript can call Windows Runtime Components written in either C++ or .NET when that function is contained in libraries or DLLs that expose Windows Metadata (WinMD) information. Unfortunately, the reverse is not the case—.NET and C++ apps cannot call a function contained in JavaScript libraries. C++ UWP apps can, however, call a function in .NET WinMD files (which are created using the Windows Runtime Component project type), and .NET code can call C++.