如何在 Windows Phone 设备上获取屏幕分辨率 [英] How to get screen resolutions on Windows Phone devices

查看:32
本文介绍了如何在 Windows Phone 设备上获取屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题,希望得到专家的帮助.我正在尝试获得屏幕分辨率,以便我可以根据手机类型使用适当的布局/图像.

I am running into issue and would appreciate expert’s help here. I am trying to get screen resolution so that I can use appropriate layouts/images based on phone types.

我的项目类型是 WP7.每当我在不同的 WP7 和 WP8 设备上运行代码时,我每次都获得相同的分辨率(800 X 480).预期的行为是我根据设备类型获得不同的分辨率,例如WVGA = 800 x 480,WXGA = 1280 x 768,720p = 1280 x 720.

My project type is WP7. Whenever I run code on different WP7 and WP8 devices, I get the same resolution everytime (800 X 480). Expected behavior is I get different resolution based on device type e.g. WVGA = 800 x 480, WXGA = 1280 x 768, 720p = 1280 x 720.

下面的所有 3 个代码片段都为我提供了相同的 800 X 480 分辨率,这不是预期的行为.

All the 3 code snippets below gave me same resolution of 800 X 480 which is not expected behavior.

Application.Current.RootVisual.RenderSize.Height + " x " + Application.Current.RootVisual.RenderSize.Width;

(App.Current.RootVisual as FrameworkElement).ActualHeight + " x " + (App.Current.RootVisual as FrameworkElement).ActualWidth;

App.Current.Host.Content.ActualHeight + " x " + App.Current.Host.Content.ActualWidth;

MSDN 文章讨论了如何在 WP8 中执行此操作,但请注意,我希望代码也能在 WP7 设备上运行.

The MSDN article talks about how to do this in WP8 but please note that I want code to run on WP7 device as well.

推荐答案

您可以尝试使用反射加载 App.Current.Host.Content.ScaleFactor.

You can try load App.Current.Host.Content.ScaleFactor using reflection.

我现在没有 wp8 环境,但是你可以看到类似的解决方案 此处.他们用它在 wp7.8 上创建王尔德瓷砖

I don't have my wp8 environment now, but you can see the similar solution here. They use it to create wilde tiles on wp7.8

这篇关于如何在 Windows Phone 设备上获取屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆