12

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

Melquiades
  • 8,496
  • 1
  • 31
  • 46
revolutionkpi
  • 2,632
  • 10
  • 45
  • 84
  • 2
    possible duplicate of [How to get screen size on Windows Phone 7 Series?](http://stackoverflow.com/questions/2596732/how-to-get-screen-size-on-windows-phone-7-series) – Katriel Mar 24 '12 at 14:16
  • What do you need it for? The resolution is the same. – Claus Jørgensen Mar 24 '12 at 14:17
  • 1
    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. – MarcinJuraszek Mar 24 '12 at 14:25

4 Answers4

21
public void GetScreenResolution()  
{  
     string ScreenWidth = Application.Current.Host.Content.ActualWidth.ToString();  
     string ScreenHeight = Application.Current.Host.Content.ActualHeight.ToString();  
     MessageBox.Show(ScreenWidth + "*" + ScreenHeight);  
}  
Dmitry Reznik
  • 6,812
  • 2
  • 32
  • 27
  • 1
    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. – hfrmobile Jul 25 '13 at 17:55
  • 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. – Seva Alekseyev Oct 20 '15 at 16:34
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

Paras Wadehra
  • 490
  • 3
  • 10
  • 2
    And what if MS adds another scalefactor for FullHD for example ? downvote for hardcode – Grigory Mar 25 '14 at 12:49
  • 2
    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. – Paras Wadehra Mar 25 '14 at 16:59
  • I would like to see your solution to this – Paras Wadehra Apr 03 '14 at 17:14
1

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

hfrmobile
  • 1,213
  • 16
  • 16
  • Seems ok, but, as described in http://stackoverflow.com/a/14018398/1130789, 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. – S0me0ne Apr 25 '14 at 10:49
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);
Community
  • 1
  • 1
Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77