在 Windows Phone 8.1 XAML 中获取设备屏幕分辨率 [英] Get device screen resolution in Windows Phone 8.1 XAML

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

问题描述

在 Windows Phone 8 中,我可以使用 DeviceExtendedPropertiesApplication.Current.Host.Content.ScaleFactor 获得屏幕分辨率.这些都不适用于 Windows Phone 8.1 XAML.

In Windows Phone 8 I can get the screen resolution using DeviceExtendedProperties or Application.Current.Host.Content.ScaleFactor. None of this works in Windows Phone 8.1 XAML.

我找不到如何在 Windows Phone 8.1 XAML 中获取屏幕分辨率的方法,有什么方法吗?

I could not find a way how to get the screen resolution in Windows Phone 8.1 XAML, is there a way?

推荐答案

使用 WinRT API 时,您可以使用 Windows.UI.Xaml.Window.Current.Bounds(高度和宽度).

When using the WinRT API, you can retrieve the screen resolution with Windows.UI.Xaml.Window.Current.Bounds (Height and Width).

您需要将这些值乘以比例因子才能获得实际分辨率.您可以通过调用 DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel

You need to multiply those values by the scale factor to get the real resolution. You can retrieve the scale factor by calling DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel

var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

Debug.WriteLine("The current resolution is {0}x{1}", Window.Current.Bounds.Width * scaleFactor, Window.Current.Bounds.Height * scaleFactor);

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

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