In general, UWP is used for making a single application that runs on Windows 10 across many different devices. However, it is also possible to make code tailored to specific devices. You can achieve this in several different ways.
Different XAML Layout
If you want to use a specific layout on for a certain "device family", you can do this by creating a new XAML Page item with the same name as the default XAML file, with a suffix to indicate the device family you are targeting. Then you'll have MainPage.xaml for all devices and MainPage.DeviceFamily-[specific family].xaml just for one specific family, which will overwrite the default layout, see below:
If you want to do this for lots of files, you can make a folder with name DeviceFamily-[specific family] and put all XAML pages into it, but now with exactly with the same name as the default XAML file (see below). In both examples, all pages would share the same code-behind file, so the functionality is identical, but the layout is tailored to specific screen sizes.
Code for specific family
If you want to run part of your code-behind or your ViewModel on a specific device family only, you can use the DeviceFamily
property from the AnalyticsVersionInfo
class.
AnalyticsVersionInfo avi = AnalyticsInfo.VersionInfo;
var deviceFamily = avi.DeviceFamily;
if(deviceFamily == "Windows.Mobile")
{
Console.WriteLine("You're on mobile device right now.");
}
else if(deviceFamily == "Windows.Desktop")
{
Console.WriteLine("You're on desktop");
}
else if(deviceFamily == "Windows.IoT")
{
Console.WriteLine("You're on IoT");
}
//....