How can I get a screen resolution of Device from settings (Windows Phone) ?
How can I get a screen resolution of Device (Windows Phone)
Asked Answered
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
public void GetScreenResolution()
{
string ScreenWidth = Application.Current.Host.Content.ActualWidth.ToString();
string ScreenHeight = Application.Current.Host.Content.ActualHeight.ToString();
MessageBox.Show(ScreenWidth + "*" + ScreenHeight);
}
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
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
And what if MS adds another scalefactor for FullHD for example ? downvote for hardcode –
Saturn
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 this –
Amortize
That solution will work on WP7.x and WP8 devices: http://sviluppomobile.blogspot.co.at/2013/04/detect-screen-resolution-for-windows.html
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
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);
Another way to know display scale is:
DisplayProperties.LogicalDpi / 96.0f
–
Resurrectionism © 2022 - 2024 — McMap. All rights reserved.