How can I get a screen resolution of Device (Windows Phone)
Asked Answered
P

4

12

How can I get a screen resolution of Device from settings (Windows Phone) ?

Pendulous answered 24/3, 2012 at 14:13 Comment(3)
possible duplicate of How to get screen size on Windows Phone 7 Series?Appealing
What do you need it for? The resolution is the same.Scintillator
It is now, but there will be more possible resolutions after next system update so it may be a good reason of that kind of questions.Blooper
R
21
public void GetScreenResolution()  
{  
     string ScreenWidth = Application.Current.Host.Content.ActualWidth.ToString();  
     string ScreenHeight = Application.Current.Host.Content.ActualHeight.ToString();  
     MessageBox.Show(ScreenWidth + "*" + ScreenHeight);  
}  
Rogozen answered 24/3, 2012 at 14:15 Comment(2)
It works of course (doing it the same way for my DeviceInfo app) but don't forget that if using SDK 7.1 (to support 7.x devices) it will result in wrong values when running on WP8.Farriery
On my Lumia 925 with WP8.1, it returns 480x800, while the specs sites out there claim the resolution is 768x1280. Something is off here.Swamper
A
6

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

Amortize answered 24/12, 2012 at 7:25 Comment(3)
And what if MS adds another scalefactor for FullHD for example ? downvote for hardcodeSaturn
This is directly from Microsoft website linked above. Of course, if new resolutions/scale factors are added, then you add another conditional in the code above. Do you think there is a way around? Don't down-vote for no reason.Amortize
I would like to see your solution to thisAmortize
F
1

That solution will work on WP7.x and WP8 devices: http://sviluppomobile.blogspot.co.at/2013/04/detect-screen-resolution-for-windows.html

Farriery answered 25/7, 2013 at 20:1 Comment(1)
Seems ok, but, as described in https://mcmap.net/q/898668/-how-can-i-get-a-screen-resolution-of-device-windows-phone, it will fail when Microsoft adds another display resolution! Especially since there is no exception handling if none of the scale factors matches. So at least add an default section to your switch condition.Gamali
A
1

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);
Armoury answered 28/7, 2015 at 1:23 Comment(1)
Another way to know display scale is: DisplayProperties.LogicalDpi / 96.0fResurrectionism

© 2022 - 2024 — McMap. All rights reserved.