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

时间:2012-03-24 14:13:01

标签: c# silverlight windows-phone-7 silverlight-4.0 silverlight-3.0

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

4 个答案:

答案 0 :(得分:21)

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

答案 1 :(得分:6)

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

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

答案 2 :(得分:1)

答案 3 :(得分:1)

这实际上需要@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);
相关问题