如何在WPF中获取当前屏幕的大小? [英] How to get the size of the current screen in WPF?

查看:519
本文介绍了如何在WPF中获取当前屏幕的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过使用

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?)

能够从XAML访问大小很高兴,但是从代码(C#)进行访问就足够了.

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

推荐答案

据我所知,没有本机WPF函数可以获取当前监视器的尺寸.相反,您可以PInvoke本机多个显示监视器功能,将它们包装在托管类中,并公开您需要从XAML使用它们的所有属性.

As far as I know there is no native WPF function to get dimensions of the current monitor. Instead you could PInvoke native multiple display monitors functions, wrap them in managed class and expose all properties you need to consume them from XAML.

这篇关于如何在WPF中获取当前屏幕的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆