Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get screen size on Windows Phone 7 Series?

How do I programatically get the screen resolution on WP7? Here are a bunch of links that get the same job done in desktop WPF and Silverlight, but none of them are in the Phone SDK.

Any ideas?

http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/f0639904-a368-44db-9ddd-efcaf8fc736e
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6b6b832f-0dfd-428c-84cd-b1b9e7f236cf
How can I get the active screen dimensions?
http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/f0639904-a368-44db-9ddd-efcaf8fc736e

like image 666
Igor Zevaka Avatar asked Apr 08 '10 00:04

Igor Zevaka


People also ask

How do I change my screen size?

On a PC, click the Start menu followed by Preferences and Display Settings. You can also right click a blank screen to access the Settings menu. Depending on your operating system you will either choose Fit to Screen or Change size of text, apps and other items.

How do I shrink my screen back to normal size using keyboard?

Click anywhere on the Windows desktop or open the webpage you want to view. Press and hold the CTRL key, and then press either the + (Plus sign) or - (Minus sign) to make objects on the screen larger or smaller. To restore normal view, press and hold the CTRL key, and then press 0.

What is diagonal screen size?

The size of a screen is usually described by the length of its diagonal, which is the distance between opposite corners, usually in inches. It is also sometimes called the physical image size to distinguish it from the "logical image size," which describes a screen's display resolution and is measured in pixels.


3 Answers

I use this:

this.ScreenWidth = System.Windows.Application.Current.Host.Content.ActualWidth;
this.ScreenHeight = System.Windows.Application.Current.Host.Content.ActualHeight;

Many ways to skin an app. If its for XAML, you could bind to the properties of the LayoutRoot.

Height="{Binding ElementName=LayoutRoot,Path=ActualHeight}"
like image 84
Luke Puplett Avatar answered Oct 03 '22 18:10

Luke Puplett


It looks like Application.Current.RootVisual.RenderSize will give you that information.

like image 29
Andréas Saudemont Avatar answered Oct 03 '22 17:10

Andréas Saudemont


I cannot down/upvote yet(actually, now I can and I did so), but I'd like to point out that "Luke Puplett"s answer including Application.Current.Host.Content is the correct one, not "Andréas Saudemont"s one that advises RenderSize.

I'll use names that are commonly used in tutorials or sample applications from MSDN.

I say that Host.Current is more adequate, because on the very very start of the application, especially on the WP7 (I dont know how it is on "regular" SL3/SL4 on PC) - that is, for example, in the very first page's constructor - the RenderSize property is NOT YET SET correctly, as the "RootVisual" of the application is being constructed and have not yet been assigned in the "App.xaml.cs". At least in that one point, the RenderSize=Size{0,0}

On the other hand, if only the App starts correctly, the Host.Content is set to some phoneframe, that is correctly full-screen-sized and rotated to the actual screen position. I'd guess that on the very start it is the starting splash screen (empty or static from JPG file)

like image 31
quetzalcoatl Avatar answered Oct 03 '22 18:10

quetzalcoatl