Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the resolution of screen? For a WinRT app?

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.

like image 635
a_rahmanshah Avatar asked May 31 '12 05:05

a_rahmanshah


2 Answers

How about this?

var bounds = Window.Current.Bounds;  double height = bounds.Height;  double width = bounds.Width; 
like image 94
Krishna Avatar answered Sep 20 '22 08:09

Krishna


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;     } 
like image 43
Thiru Avatar answered Sep 20 '22 08:09

Thiru