Windows 10 Development Adaptive Code - Windows 10 Development

What is Windows 10 Development Adaptive Code?

In this section, we will be representing the acceptance of your application to different devices held by Windows 10. We have previously educated about adopting your UI and all the tricks, techniques and controls used in UWP applications.

Currently, we will learn about accepting your code, because

  • Application codes are not the same across all the devices.
  • APIs used, particularly for Xbox, will not be available for mobile devices. The same thing is true for HoloLens etc.


Adaptive code can light up your application temporarily and execute code only when running on a particular device family and/or on a particular version of the platform/extension APIs.

Writing Code

In Windows 10, you can implement the UWP applications in Visual Studio by using either C++, C#, Visual Basic or JavaScript.

  • With C# and Visual Basic you can use XAML for UI designing.
  • With C++ you can either use DirectX instead of using XAML.
  • For JavaScript, you can use HTML for your presentation layer, which is a cross platform Web standards.

The Windows Core APIs run in the similar way for all the devices, which comprise most of the functionality you need for your code and UI.

Though, for the code and the UI tailored for specific device families, you need to use the adaptive code and adaptive UI.

Calling an API that is NOT implemented by the target device family −

The UI adapts to changed screens easily, but altered device families not only have different screen sizes, it has a lot more than that.

  • For instance, the mobile phones have some hardware buttons such as Back and Camera, which might not be obtainable on other devices such as PC.
  • By default, the core APIs comprise most of the functionality, which works for all the devices, but the device precise functionality can be used by referencing the Extension SDKs in your UWP applications just like external assemblies.

To add any particular extension SDK, needed in your application, follow the below given steps −

  • Right click on the References.
  • Select “Add References..”. The following dialog will open.


  • Adding an extension is as simple as adding a project reference.
  • Currently you can add any extension SDK from the list, which comprises Desktop Extension, IoT Extension, and Mobile Extension etc.

Desktop and Mobile extensions are the two most mutual platform Extension SDKs. The Mobile extension, for instance, enables the APIs essential to use the hardware camera button.

You can check the device competences by using the Windows.Foundation.Metadata.ApiInformation class method, which returns a Boolean output if the type is supported on the current device. For example, you can enable your Windows app to use the Camera button with code like this –

The phone-camera button code will perform only if the Mobile Extension SDK is enabled on the device. Likewise, you can also check for any precise event, method or property in the current API version by using IsEventPresent, IsMethodPresent, IsPropertyPresent, instead of IsTypePresent as shown below.

Win32 APIs in the UWP

A Universal Widows Platform (UWP) application or Windows Runtime Component, which are written in C++/CX, can access Win32 APIs, which are also a part of UWP now. All of the Windows 10 device families can implement Win32 APIs by linking your application with Windowsapp.lib.
Windowsapp.lib is an "umbrella" lib that delivers the spreads for the UWP APIs. Linking to Windowsapp.lib will add to your app addictions on dllsthat are present on all Windows 10 device families.

Let us have a look into an easy instance in which the application targets both the desktop and the phone. As a result, when the application runs on the desktop, it will not show the status bar, but when the same application runs on the phone, it will display the status bar.
Given below is the XAML code in which different controls are added.

Given below is the C# implementation for different events.

When the above given code is compiled and executed on a Mobile, you will see the resulting window.

You can modify the background color of the status bar with the checkbox as shown in the image.

You can also hide the status bar.

Currently, when you run the similar application on a desktop device, you will see the resulting window in which the status bar and the checkboxes exact to the status bar are not visible.


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Windows 10 Development Topics