【发布时间】:2012-03-24 14:13:01
【问题描述】:
如何从设置中获取设备的屏幕分辨率(Windows Phone)?
【问题讨论】:
-
你需要它做什么?分辨率是一样的。
-
现在是,但是下次系统更新后会有更多可能的解决方案,所以这可能是这类问题的一个很好的理由。
标签: c# silverlight windows-phone-7 silverlight-4.0 silverlight-3.0
如何从设置中获取设备的屏幕分辨率(Windows Phone)?
【问题讨论】:
标签: c# silverlight windows-phone-7 silverlight-4.0 silverlight-3.0
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.x 和 WP8 设备: 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);
【讨论】:
DisplayProperties.LogicalDpi / 96.0f