1

I am using below C# code to get the screen size of the monitor in UWP.

var displayInformation = DisplayInformation.GetForCurrentView();
var screenSize = new Size((int)displayInformation.ScreenWidthInRawPixels,
                                      (int)displayInformation.ScreenHeightInRawPixels);

But the problem is it returns first monitor resolution. I have two monitors and I need to screen size of the monitor where the app is run. not first monitor. If the app runs on the second monitor then I need screen size of the second monitor instead of the first monitor. My monitor size is different.

How can I solve this puzzle?

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
John Smith
  • 139
  • 8
  • Possible duplicate of [Get Screen Resolution in Win10 UWP App](https://stackoverflow.com/questions/31936154/get-screen-resolution-in-win10-uwp-app) – McNline May 29 '19 at 07:50

1 Answers1

0

That should actually be the behavior you will be getting - once you move your app to another screen, DisplayInformation properties will start returning values for that given screen.

I have tested it locally as well - you don't even have to get a new instance via GetForCurrentView - even if you just have one instance, calling ScreenWidthInRawPixels and similar properties when your app moves to the second screen, you will be getting the correct values.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • Thanks for answer but I need to set app size while app is load. so like if screen resolution is 1600x 900 then I need to set app size 400x400 and if screen resolution is 1280x1080 then I need to set app size 300x300. – John Smith May 29 '19 at 09:41
  • That should be fine still - `DisplayInformation` should return the correct values according to the screen the app launches on – Martin Zikmund May 29 '19 at 10:20