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.aspxstring 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);
}
页:
[1]