【发布时间】:2011-07-14 11:26:26
【问题描述】:
我正在 WPF 中创建类似记事本的应用程序。我想根据屏幕尺寸设置窗体的高度和宽度。如何获得屏幕高度和宽度?
【问题讨论】:
-
是的。不应该假设 SO 是一个自动应答机,可以节省搜索网络。
-
如果你想让窗口适应屏幕大小,为什么不最大化它呢?
-
Google 将我重定向到这里作为首选 ;-)
标签: wpf
我正在 WPF 中创建类似记事本的应用程序。我想根据屏幕尺寸设置窗体的高度和宽度。如何获得屏幕高度和宽度?
【问题讨论】:
标签: wpf
只需将SystemParameters 属性绑定到您的窗口属性即可。
<Window x:Class="YourWindow"
Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}">
【讨论】:
见System.Windows.SystemParameters
你有类似的属性
PrimaryScreenWidthPrimaryScreenHeightVirtualScreenHeightVirtualScreenWidthWorkArea等等
这个问题也可能有帮助:How can I get the active screen dimensions?
【讨论】: