Reputation: 2210
How would one go about getting the bounds for each physical display from a UWP application? I used to be able to do this:
System.Windows.Forms.Screen.AllScreens;
I've seen examples using
DisplayInformation.GetForCurrentView();
But that only gets the size of the screen the application is currently running on. I have a vertical screen application that I'm building and I would like it to always start on my vertical monitor instead of my primary horizontal monitor. I understand UWP apps should be resolution agnostic, but this isn't the case here. This is an application designed to work on a very particular display.
Please, this is UWP question only. This Question was written 6 years before UWP was even a thing. This is not a duplicate.
Upvotes: 1
Views: 1298
Reputation: 92
You can use code like this
var deviceSelector = DisplayMonitor.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(deviceSelector);
foreach (var device in devices)
{
var monitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id);
var monitorSize = monitor.NativeResolutionInRawPixels;
}
Upvotes: 2
Reputation: 39092
It indeed seems there is no API that can achieve this currently in UWP. You can post this idea to UWP UserVoice so that it is considered as something you would want.
The best you can do is query the resolution of the monitor the app is running on as you stated and also enumerating all monitors using ProjectionManager
:
var deviceSelector = ProjectionManager.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(deviceSelector);
foreach (var device in devices)
{
Debug.WriteLine("Kind: {0} Name: {1} Id: {2}", device.Kind, device.Name, device.Id);
foreach (var property in device.Properties)
{
Debug.WriteLine( property.Key + " " + property.Value);
}
}
Unfortunately the device properties don't contain resolution information that you could use.
Upvotes: 2