0

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.

Chris Lees
  • 2,140
  • 3
  • 21
  • 41

2 Answers2

1

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.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • Thanks @Martin! I'm starting to think I should just stick with WPF. UWP might not be for me. I find it so hard to believe how crippled UWP is. I understand it supposed to be a sandbox, but man it's incredibly limited. – Chris Lees May 17 '18 at 14:11
  • It is getting more and more APIs with each update :-) . But now with the new features announced at Build you can start with WPF and continuously upgrade it to UWP including UI with XAML Islands and Runtime using .NET Core 3.0. You can even use parts of Fluent Design System in WPF app – Martin Zikmund May 17 '18 at 14:13
  • And WPF apps can go into Store anyway, so it is not a big issue per se :-) – Martin Zikmund May 17 '18 at 14:15
1

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;
        }