【问题标题】:Proper way to detect that a UWP app is running on a small-screen device (phone)检测 UWP 应用程序是否在小屏幕设备(手机)上运行的正确方法
【发布时间】:2016-04-26 15:35:32
【问题描述】:

阅读了有关this 的内容后,我觉得关于检测 UWP 应用是否在适合仅纵向显示的设备上运行仍有一个未解决的问题。

我们的 UWP 应用的最佳页面布局是,在手机上,我们最好禁用横向模式(对于较大格式的设备,我们不需要这样的限制)。实现这一目标的最佳实践方法是什么?

【问题讨论】:

  • 有点倒退,不是吗?屏幕越小,转动越容易。使用 DisplayInformation 类。

标签: c# screen-orientation uwp


【解决方案1】:

您可以使用AnalyticsInfo.VersionInfo.DeviceFamily 检测设备系列。

if(AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") {
    // It's a phone
}
else {
    // It's not a phone
}

【讨论】:

  • 简单高效的方法。 +1。
【解决方案2】:
 if ((Window.Current.Bounds.Width < 640) && (Window.Current.Bounds.Height < 550))
                {
                          //Do something
                }

祝你好运。

【讨论】:

    【解决方案3】:

    您也可以测试硬件按钮的可用性,但不是每部手机都有!

    public  Platform DetectPlatform()
            {
                bool isHardwareButtonsAPIPresent = ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");
    
                if (isHardwareButtonsAPIPresent)
                {
                    return Platform.WindowsPhone;
                }
                else
                {
                    return Platform.Windows;
                }
            }
    

    【讨论】:

      【解决方案4】:

      您可以检查硬件后退按钮。 Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")

      【讨论】:

      • 这种情况下的Surface tablet是什么?手机还是台式机?
      猜你喜欢
      • 1970-01-01
      • 2017-06-27
      • 2011-08-12
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 2012-03-22
      相关资源
      最近更新 更多