UWP Tips & Tricks #5 – Detect DeviceFamily in Windows App

Since the Universal Windows Platform (UWP) apps run on all the devices powered by Window 10 , you might sometimes want to target a specific device family(eg : mobile or desktop) for certain features.

How to Detect DeviceFamily in UWP Apps ?

You can use the property VersionInfo.DeviceFamily that is defined in the AnalyticsInfo class as shown below.

var DeviceFamily = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
MessageDialog dialog = new MessageDialog(DeviceFamily);
dialog.ShowAsync();

When you run your UWP app on a desktop environment and using the Local Machine option for deployment , the device family will be displayed as Windows.Desktop.

image

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.