I want to know the screen resolution so that I can set the height of an element according to the resolution in a Windows 8 app.
How about this?
var bounds = Window.Current.Bounds; double height = bounds.Height; double width = bounds.Width;
Getting the bounds of current window is easy. But say if you want to set a large font size for bigger screen (resolution is same as 10" device, but screen is 27"), this wont help. Refer Scaling to different screens I used the following method to detect screen size & change text block font style appropriately.
void detectScreenType() { double dpi = DisplayProperties.LogicalDpi; var bounds = Window.Current.Bounds; double h; switch (ApplicationView.Value) { case ApplicationViewState.Filled: h = bounds.Height; break; case ApplicationViewState.FullScreenLandscape: h = bounds.Height; break; case ApplicationViewState.Snapped: h = bounds.Height; break; case ApplicationViewState.FullScreenPortrait: h = bounds.Width; break; default: return; } double inches = h / dpi ; string screenType = "Slate"; if (inches < 10) { screenType = "Slate"; } else if (inches < 14) { screenType = "WorkHorsePC"; } else { screenType = "FamilyHub"; } ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["screenType"] = screenType; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With