2

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?

Saif Al Falah
  • 358
  • 5
  • 16

3 Answers3

3

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.

Faster Solutions
  • 7,005
  • 3
  • 29
  • 45
  • I did figure it out. I am now designing for a base resolution of 1366x768 putting all of my UI into a Viewbox control. It's working pretty well up till now. – Saif Al Falah Oct 16 '12 at 16:28
  • 1
    It gives current size of the app windows not the system, if may produce false results when screen is in snapped view – Jayant Varshney Mar 05 '13 at 11:00
  • By default Windows store apps design for the screen which has screen size 10.6" and resolution 1366*768.If I want to design my app for every screen size and every resolution?Is there any way to do it? – Pranav Mahajan Nov 18 '14 at 10:55
2

Anything these two articles don't explain?

Guidelines for scaling to screens (Windows Store apps)

Building Windows 8 : Scaling to different screens

Euphoric
  • 12,645
  • 1
  • 30
  • 44
  • The first link did help me. I am now designing for a base resolution of 1366x768 putting all of my UI into a Viewbox control. It's working pretty well up till now. – Saif Al Falah Oct 16 '12 at 16:29
2
Windows.Graphics.Display.DisplayProperties.LogicalDpi
Ketobomb
  • 2,108
  • 1
  • 17
  • 27
  • I'm going to upvote this cryptic answer, because this helped my issue, unlike every other answer. I was looking to get device screen resolution from logical WinRT pixel dimensions. Logical pixel width x (logical dpi / 96) gives me device pixel width. – Daniel S. Dec 20 '13 at 23:57
  • Why did you divided to 96? – Mark Feb 11 '15 at 21:42