2011-03-13 214 views
5

我正在WPF中创建一个类似于应用程序的记事本。我想根据屏幕大小设置窗体的高度和宽度。我如何获得屏幕高度和宽度?WPF窗口大小

+0

Screen.PrimaryScreen.Bounds – 2011-03-13 14:20:06

+0

是的。不应该假设它是一个节省搜索网络的自动答录机。 – 2011-03-13 14:28:54

+2

如果你想让窗口适合屏幕尺寸,为什么不把它最大化呢? – 2011-03-13 17:34:29

回答

8

只需绑定SystemParameters属性的窗口属性。

<Window x:Class="YourWindow" 
    Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}" 
    Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}"> 
+2

SystemParameters提供所有属性的资源键。最好使用DynamicResource而不是绑定。 – 2011-03-13 20:47:18

+0

这不是在这里工作。 “Windows Presentation Foundation(WPF)项目不支持”SystemParameters“。”耻辱:| – Malavos 2014-02-10 11:56:36