21

I'm trying to create a WPF window that will encompass the entire Desktop working area. In WinForms I'd do this by getting the Union of all the bounds in System.Windows.Forms.Screen.AllScreens.

Is there an equivalent type or other mechanism to get the bounds of the entire desktop in WPF or do I need to use the WinForms type?

ChrisF
  • 134,786
  • 31
  • 255
  • 325
dkackman
  • 15,179
  • 13
  • 69
  • 123

4 Answers4

18

Try SystemParameters.VirtualScreen* (Top, Left, Height, and Width) properties. http://msdn.microsoft.com/en-us/library/system.windows.systemparameters.virtualscreenheight(v=VS.100).aspx

Don't use winforms api because it doesn't take into account the fact that WPF's measurement units are not pixels. I came across this issue just recently because I'm losing my vision and have my monitor set to a higher dpi. The codebase I was working on used the Winforms Settings and the UI was larger than my screen.

If you're going to use the winforms api. Look at this blog post on calculating the DPI factor.

Michael Brown
  • 9,041
  • 1
  • 28
  • 37
  • 2
    Just to point it out bluntly: this does _precisely_ what OP wanted, and nothing more. Whereas `Screen` can enumerate each monitor separately, `VirtualScreen` is _only_ the total area. – DonBoitnott Dec 10 '18 at 21:00
14

I have successfully used WpfScreenHelper 0.3.0.0, currently on Github or Nuget, https://github.com/micdenny/WpfScreenHelper

It does what the .NET framework should have done so many years ago. I needed to check if some coordinates exist on any screen in WPF, as in these:

Community
  • 1
  • 1
geac
  • 141
  • 1
  • 2
2

Just use WinForms. I do not think there is a direct WPF equivalent.

wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
  • 1
    Wrong there are WPF Equivalents. See my response. – Michael Brown Apr 25 '10 at 04:49
  • 16
    Oh? Can WPF tell us about each monitor individually? Can WPF tell you which screen a window is on (like Screen.FromControl()?) – Qwertie Jul 29 '11 at 21:24
  • 6
    What if you have multiple monitors with not equal size? Is there any equivalent to handle this? and as Qwertie mentioned which screen it is? – Marek Aug 30 '12 at 08:41
  • How does such answers get up voted? This is no answer AT ALL. – Yves Calaci Feb 19 '21 at 22:51
  • 1
    The problem with importing winforms is that it becomes far too easy to accidentally reference winforms types instead of wpf types, which ends up polluting wpf code with non-portable cruft. All of a sudden there are literally two types for *everything*, one of them being an unwanted WInForms type. DON'T DO IT!!! – Robin Davies Jan 09 '22 at 22:03
1

You could try SystemParameters.VirtualScreenWidth and associated parameters. That might not provide as good as a result as continuing with the WinForms API.

The only downside I can see with the WinForms type is an extra dependency and the larger working set related to that.

nedruod
  • 1,122
  • 2
  • 9
  • 19