Alex Rivera | Logout

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

Asked 2009-12-18T11:02:16.483
124

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.

Edit
Report

1 Answer

17

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.

answered 2009-12-18T11:17:09.953

Your Answer