简体   繁体   中英

How can I get a screen resolution of Device (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);  
}  

This may be a better way to know what screen resolution is your app running on.

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
}

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

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

This actually requires a combination of @Dmitriy Reznik and @Paras Wadehra 's answers, as the dimensions exposed by Host.Content are the unscaled dimensions.

var content = App.Current.Host.Content;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM