WPF窗口大小

Dur*_*utt 5 wpf

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

Kyr*_*o M 9

只需将SystemParameters属性绑定到窗口属性即可.

<Window x:Class="YourWindow"
    Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}" 
    Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}">
Run Code Online (Sandbox Code Playgroud)

  • SystemParameters为其所有属性提供资源键.最好使用DynamicResource而不是绑定. (2认同)

Fre*_*lad 8

请参见System.Windows.SystemParameters

你有像这样的属性

  • PrimaryScreenWidth
  • PrimaryScreenHeight
  • VirtualScreenHeight
  • VirtualScreenWidth
  • WorkArea

等等

这个问题也可能有所帮助:如何获得活动屏幕尺寸?