How to check if Windows device is phone or tablet/pc?

半世苍凉 提交于 2019-12-20 03:19:28

问题


How to check if Windows device is phone or tablet/PC? I need to know in order to use different sizes for xaml elements


回答1:


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.




回答2:


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.




回答3:


    public static bool DeviceIsPhone()
    {
        Type StatusBarType = Type.GetType("Windows.UI.ViewManagement.StatusBar, Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime");
        if (StatusBarType != null)
            return true;
        return false;
    }


来源:https://stackoverflow.com/questions/30727681/how-to-check-if-windows-device-is-phone-or-tablet-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!