How to check if Windows device is phone or tablet/PC? I need to know in order to use different sizes for xaml elements
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I think you can try to use EasClientDeviceInformation class:
on WP it should return
WindowsPhone
andWindows
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:
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.