我怎样从设置(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/zh-cn/library/windowsphone/develop/jj206974(v=vs.105).aspx
这是关于Windows Phone开发的官方文档。其中包括了许多有用的信息,如应用程序生命周期、XAML布局、触摸输入和网络通信等方面的内容。如果您正在开发Windows Phone应用程序,这篇文章将会对您非常有帮助。这个解决方案适用于WP7.x和WP8设备: http://sviluppomobile.blogspot.co.at/2013/04/detect-screen-resolution-for-windows.html
Host.Content
暴露的尺寸是未缩放的尺寸。var content = App.Current.Host.Content;
var screenResolution = new Size(
content.ActualWidth*content.ScaleFactor/100,
content.ActualHeight*content.ScaleFactor/100);
DisplayProperties.LogicalDpi / 96.0f
- Igor