【问题标题】:WPF window sizeWPF 窗口大小
【发布时间】:2011-07-14 11:26:26
【问题描述】:

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

【问题讨论】:

  • 是的。不应该假设 SO 是一个自动应答机,可以节省搜索网络。
  • 如果你想让窗口适应屏幕大小,为什么不最大化它呢?
  • Google 将我重定向到这里作为首选 ;-)

标签: wpf


【解决方案1】:

只需将SystemParameters 属性绑定到您的窗口属性即可。

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

【讨论】:

  • SystemParameters 为其所有属性提供资源键。最好使用 DynamicResource 而不是绑定。
  • 这在这里不起作用。 “Windows Presentation Foundation (WPF) 项目不支持 SystemParameters。”可惜了:|
【解决方案2】:

System.Windows.SystemParameters

你有类似的属性

  • PrimaryScreenWidth
  • PrimaryScreenHeight
  • VirtualScreenHeight
  • VirtualScreenWidth
  • WorkArea

等等

这个问题也可能有帮助:How can I get the active screen dimensions?

【讨论】:

    猜你喜欢
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2019-07-26
    相关资源
    最近更新 更多