Windows Phone 8 学习备忘(如何获取手机屏幕的物理尺寸)

WP8的机子升级到WP8.1的Preview后,发现6寸屏幕的机器,键盘弹起的高度和以前不一样了,App Bar的高度和里面的字体大小不一样了,为了适配这一个变化,必须得获取到手机屏幕的物理尺寸进行特殊处理,搜了一大圈,最后终于找到了这个间接的接口,微软你的API藏的够深的http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/11/22/taking-advantage-of-large-screen-windows-phones.aspx

string GetExtendedScreenInfo()

{

  object temp;

  if (!DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out temp))

    return "not available, sorry";

 

  var screenResolution = (Size)temp;

 

  // Can query for RawDpiY as well, but it will be the same value

  if (!DeviceExtendedProperties.TryGetValue("RawDpiX", out temp) || (double)temp == 0d)

    return "not available, sorry";

 

  var dpi = (double)temp;

  var screenDiagonal = Math.Sqrt(Math.Pow(screenResolution.Width / dpi, 2) +

  Math.Pow(screenResolution.Height / dpi, 2));

 

  var width = App.Current.Host.Content.ActualWidth;

 

  return String.Format("{0} x {1}; {2:0.0#} raw scale; {3:0.0}"",

    screenResolution.Width, screenResolution.Height, screenResolution.Width / width,

    screenDiagonal);

}

 

作者:Le Ruin
出处:http://www.cnblogs.com/leluyun/
关于作者:专注于Windows Phone 开发
Windows Phone Store上不再有作者独立开发的程序,但作者依然还在开发的路上前行。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过新浪微博 leluyun@hotmail.com 联系我,非常感谢。

原文地址:https://www.cnblogs.com/leluyun/p/3672707.html