如何获取设备(Windows Phone)的屏幕分辨率

本文关键字:Phone 屏幕 分辨率 Windows 何获取 获取 | 更新日期: 2023-09-27 18:28:49

如何从设置中获得设备的屏幕分辨率(Windows Phone)?

如何获取设备(Windows Phone)的屏幕分辨率

public void GetScreenResolution()  
{  
     string ScreenWidth = Application.Current.Host.Content.ActualWidth.ToString();  
     string ScreenHeight = Application.Current.Host.Content.ActualHeight.ToString();  
     MessageBox.Show(ScreenWidth + "*" + ScreenHeight);  
}  

这可能是了解应用程序运行的屏幕分辨率的更好方法。

if(App.Current.Host.Content.ScaleFactor == 100)
{
  // WVGA
}
else if (App.Current.Host.Content.ScaleFactor == 160)
{
  // WXGA
}
else if (App.Current.Host.Content.ScaleFactor == 150)
{
  // 720p
}

来源http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206974%28v=vs.105%29.aspx

该解决方案将适用于WP7.xWP8设备:http://sviluppomobile.blogspot.co.at/2013/04/detect-screen-resolution-for-windows.html

这实际上需要@Dmitriy Reznik和@Paras Wadehra的答案的组合,因为Host.Content暴露的维度是未缩放的维度。

var content = App.Current.Host.Content;
var screenResolution = new Size(
    content.ActualWidth*content.ScaleFactor/100,
    content.ActualHeight*content.ScaleFactor/100);