Subscribe to our YouTube Channel for more Videos

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

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.