Search code examples
c#wpfxamlsizescreen

How to get the size of the current screen in WPF?


I know I can get the size of the primary screen by using

System.Windows.SystemParameters.PrimaryScreenWidth;
System.Windows.SystemParameters.PrimaryScreenHeight;

But how do I get the size of the current screen? (Multi-Screen users do not always use the primary screen and not all screens are using the same resolution, right?)

It would be nice to be able to acces the size from XAML, but doing so from code (C#) would suffice.


Solution

  • As far as I know, there is no native WPF method(s) to get the dimensions of a given monitor. Instead, you could PInvoke native Multiple Display Monitors Functions, wrap them in a managed class (or use Microsoft's official CsWin32 Nuget package) and expose all properties you need to consume from XAML.