How to check if Windows device is phone or tablet/PC? I need to know in order to use different sizes for xaml elements
How to check if Windows device is phone or tablet/pc?
2.2k views Asked by ventura8 AtThere are 3 answers
I think you can try to use EasClientDeviceInformation class:
EasClientDeviceInformation info = new EasClientDeviceInformation();
string system = info.OperatingSystem;
on WP it should return WindowsPhone
and Windows
on desktop.
You shouldn't use different sized Xaml based on if it's a phone or a tablet. You should use different Xaml based on the size and resolution of the screen.
On Windows 8.1 there are enough Xaml differences that you may be stuck needing to do different things for Phone and PC/Tablet, but in that case you will generally use different Xaml files for the two projects. You can also two versions of a resource dictionary with phone and PC/Tablet specific styles and place them in the platform specific projects to get different behavior on each device.
If you really want to know this from code, on 8.1 you always use different binaries for phone and for tablet: you can just compile it in with compile-time constants:
bool IsAPhone()
{
#if WINDOWS_PHONE_APP
return true;
#else
return false;
#endif
}
On Windows 10 you'll use the same binary and the same Xaml API for both, and the same device may display on both a small (phone) screen and a large one.
While you can still use separate Xaml files to tailor the UI for different devices you can also use responsive techniques (Visual States and AdaptiveTriggers, RelativePanels, etc.) to reflow the UI for the window size so the same app can provide different but appropriate views depending on the size of the screen regardless of the device the app runs on.
Take a look at the Build session Design: UX Patterns and Responsive Techniques for Universal Windows Apps for more details.