我正在WPF中创建一个类似于应用程序的记事本。我想根据屏幕尺寸设置窗口高度和宽度。如何获得屏幕高度和宽度?
答案 0 :(得分:8)
请参阅System.Windows.SystemParameters
你有像
这样的属性PrimaryScreenWidth
PrimaryScreenHeight
VirtualScreenHeight
VirtualScreenWidth
WorkArea
等
答案 1 :(得分:8)
只需将SystemParameters
属性绑定到您的窗口属性即可。
<Window x:Class="YourWindow"
Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}">