0

Is there a way to get the screen resolution in WinRt app? I know in windows phone it's possible:

 var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
    var bounds = Window.Current.Bounds;

        var x = (int) (bounds.Width*scaleFactor);
        var y = (int) (bounds.Height*scaleFactor);

      var resolution = String.Format("{0}x{1}", Math.Max(x, y),Math.Min(x,y));


But in winrt I don't have the RawPixelsPerViewPixel method...

Any ideas?

I've tried to follow the Detect screen scaling factor in Windows 8.1 store apps post :

ResolutionScale resolutionScale = DisplayInformation.GetForCurrentView().ResolutionScale;

    double scale = (double)resolutionScale / 100.0;

    var bounds = Window.Current.Bounds;

    var x = (int)(bounds.Width * scale ) ;
    var y = (int)(bounds.Height * scale );


    var resolution = String.Format("{0}x{1}", Math.Max(x, y), Math.Min(x,y) );

But I am getting wrong numbers, for resolution 1920 x 1080 I get "1920x1008" and for resolution 800 x 600 I get "1126x743"

Community
  • 1
  • 1
Pavel Durov
  • 1,287
  • 2
  • 13
  • 28
  • Possible duplicate of [Detect screen scaling factor in Windows 8.1 store apps](http://stackoverflow.com/questions/22157443/detect-screen-scaling-factor-in-windows-8-1-store-apps) – Kevin Gosse Oct 28 '15 at 19:12
  • Well, that post didn't really answers my question...I want to get the screen resolution - for instance : 720 x 1280 – Pavel Durov Oct 28 '15 at 19:20
  • Well, once you have the scale factor, you can apply the same algorithm as the one you provided – Kevin Gosse Oct 28 '15 at 19:46
  • I've tried, and I am getting something like : "1920x1008" when my screen resolution set to 1920 x 1080, when I am changing the resolution to something else, for example : 800 x 600 I am getting : "1126x743" – Pavel Durov Oct 29 '15 at 06:45

2 Answers2

0

Try this one:

 var devices = PointerDevice.GetPointerDevices();
 var rect = devices.FirstOrDefault().ScreenRect;
 var dpi = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
 var width = rect.Width * dpi;
 var height = rect.Height * dpi;

This should work for both Desktop and Mobile in UWP apps.

JuniperPhoton
  • 736
  • 5
  • 14
0

I have a solution, based on a hack that I saw once for getting the Info about the Operating system in WinRT 8.1 app. I've created a temporary web view and navigated to string, in that html string I've called window.external.notify with javascript info about the resolution:

 var resolution = Math.max(window.screen.width, window.screen.height)  
                        + " x " + Math.min(window.screen.width, window.screen.height);

Then, in C# code I am receiving the parameter as webView event called. I am not really satisfied with this solution, although it works fine...

Pavel Durov
  • 1,287
  • 2
  • 13
  • 28