Saif Al Falah
Saif Al Falah

Reputation: 358

Screen resolution detection in Windows 8 Apps

Is there a way I can detect the resolution of the screen in a Windows 8 app so that I can scale and resize the elements of the UI accordingly?

If not then what is the best way to go about developing an app that is resolution independent? Is there a standard way that I am not aware of or is there some other way this can be achieved?

Upvotes: 2

Views: 6689

Answers (3)

Christian Regli
Christian Regli

Reputation: 2246

Windows.Graphics.Display.DisplayProperties.LogicalDpi

Upvotes: 2

Faster Solutions
Faster Solutions

Reputation: 7005

Anything that inherits from FrameworkElement has a SizeChanged event. This event returns the current size of the framework element.

To get the overall size of the screen you can use:

Windows.UI.Xaml.Window.Current.Bounds.Height
Windows.UI.Xaml.Window.Current.Bounds.Width

Be careful as this will return the size of the screen and you will need to take into account whether your app is full-screen or Snapped/Filled.

Microsoft guidance says that you should be avoiding absolute values for height/width and simply setting HorizontalAlignment and VerticalAlignment to Stretch to allow the UI to take as much space as it needs to render.

Upvotes: 3

Related Questions