Windows Dev Center

Build UWP apps with Visual Studio

The Universal Windows app experience has improved significantly for Windows 10 from the Windows 8.1 experience. This topic explains how you create Universal Windows apps for Windows 10 devices and covers some of the differences.

With the introduction of the single, unified Windows 10 core and the Universal Windows Platform (UWP), one app package can run across all platforms. You now build one Universal Windows app that runs on all Windows 10 devices. Run your app on a Windows 10 phone, a Windows 10 desktop, or Xbox. It’s the same app package! You can design your pages so they render properly no matter what device is used to view them.

If you want to get a sense of what’s possible, have a look at this UWP guide. Then, go ahead and build your first truly universal Windows app.

Get started with Universal Windows apps

First download and do a custom install of Microsoft Visual Studio. Make sure that the Universal Windows App Development Tools are selected from the optional features list. Without these tools, you won't be able to create your Windows 10 universal apps.

When you install Visual Studio, add these optional features

When you develop apps or test an app on a Windows 10 device, you must enable that device for development. You no longer need a developer license with Windows 10. Follow the steps here to enable your device.

Now you are ready! Choose the template based on the language that you want to use: C#, Visual Basic, C++ or JavaScript. (In this topic, we are using a C# template.) Next create a Blank App (Universal Windows) project.

Windows 10 universal app blank template in Visual Studio

When you've done that, notice that only one project appears in Solution Explorer. That's because your app is now truly adaptive and you only need one project to build it.

The project contains one page but you can add others. Each page renders on all devices that your project targets so you don't have to create multiple versions of them. If you want to optimize the experience of a page for a specific device, you most certainly can. We'll discuss that shortly.

Windows 10 universal app in Solution Explorer

Add universal controls that adapt to your Windows 10 devices

The UWP introduces some new controls, such as the RelativePanel and SplitView controls, that adapt their appearance for different types of devices, layouts, and device orientations.

Learn more about adaptive controls.

Preview your pages on different devices

You can see how a page renders on different devices without having to run your app on each device. Choose a device from a drop-down list at the top of your designer. The dimensions of the page that appears in your designer change with each selection. You can also choose to view your page in landscape or portrait mode.

View UI for different device sizes and resolutions

Run your app and debug your code

To run your app, choose a device target from the drop-down list next to the Local Machine button on the Standard toolbar.

Drop-down list of device targets for debugging your app

To see how your app appears on a tablet or desktop, run it locally, on a remote machine, or in a simulator. The simulator helps you simulate common touch and rotation events.

To see how your app appears on a different Windows device, choose an emulator or attach a device directly to your computer. To run the app with any of the emulators, you need to install Visual Studio on a physical machine. The physical machine must run Windows 8.1 (x64) Professional edition or higher, and have a processor that supports Client Hyper-V and Second Level Address Translation (SLAT). The emulators cannot run when Visual Studio is installed on a virtual machine.

Learn more about how to run your app in each of these device targets.

Learn more about how to debug and test your app in Visual Studio

Add platform-specific code

Most of your code will run on both PCs and mobile devices. Most likely, you won't have to do anything to make that happen. That's because most APIs have been converged into a single Universal Windows SDK. You can find that SDK in your list of project references in Solution Explorer.

However, sometimes, you'll have to write code that runs only on a specific device family. To do that, open the Reference Manager dialog box, and then choose one of the Extension SDKs for the Universal Windows Platform (UWP) depending on the device families that your code needs to target. (Over time there may be more extension SDKs added for other device families.)

Add any extension SDKs that you need for your app

You'll have to make sure that an API is available on the running device before you use it. For example, this code assigns an event handler to the Windows.Phone.UI.Input.HardwareButtons.CameraPressed event. The code compiles if your project contains a reference to the Windows Mobile Extensions for the UWP SDK.


Windows.Phone.UI.Input.HardwareButtons.CameraPressed += HardwareButtons_CameraPressed;

But what happens when a user runs this app on a PC without a camera button? The app would crash because a PC does not have a back button.

To address this issue, use the Windows.Foundation.Metadata.ApiInformation.IsTypePresent method to determine whether a type named Windows.Phone.UI.Input.HardwareButtons is available on the running device. If it is, then the app is running on a mobile device, and the code will execute without crashing the app. The following code does that.


// Note: Cache the value instead of querying it more than once.
    bool isHardwareButtonsAPIPresent =
        Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");

    if (isHardwareButtonsAPIPresent)
    {
        Windows.Phone.UI.Input.HardwareButtons.CameraPressed +=
            HardwareButtons_CameraPressed;
    }



Use this pattern throughout your app to add device-specific functionality to your app experience.

Handle different orientations or screen dimensions

Use adaptive triggers in your XAML to specify how controls should appear based on things like the orientation of the device. You can only add adaptive triggers using Blend and not Microsoft Visual Studio 2015.

Learn how to add adaptive triggers.

Create a device-specific view for a page

Sometimes you need more than adaptive controls and design states to achieve a tailored experience. No problem there. You can create device-specific views for your pages. they're not separate pages because they share the same code behind file.

Learn more about Views.

Port existing apps

Learn what changes you need to make to port an existing Windows 8.1 universal app, or a Universal Windows app that you created with Visual Studio 2015 RC, to use the latest UWP and then run your app on any Windows 10 device.

Release notes for Visual Studio 2015

Review the release notes.

Q&A

Q: Can I add my Universal Windows apps to the Windows Store now?

A: Yes. First you need to package your app.

Related topics

UWP guide
Port an existing Windows 8 universal app
Universal Windows apps
Build a Windows 8.1 universal app

 

 

Show:
© 2015 Microsoft