Reputation: 358
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
Reputation: 12849
Anything these two articles don't explain?
Guidelines for scaling to screens (Windows Store apps)
Building Windows 8 : Scaling to different screens
Upvotes: 2
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