WPF应用程序最大化问题

时间:2010-04-29 14:37:31

标签: wpf window

如何在最大化时设置WPF应用程序的高度和宽度? 我面临的问题是因为不同计算机中Windows任务栏的高度可变

目前,我这样做。请建议任何更好的技术

if (this.WindowState == WindowState.Maximized) { this.Height = primaryScreenHeight - 10 - System.Windows.Forms.SystemInformation.SizingBorderWidth; this.Width = primaryScreenWidth + 2 * System.Windows.Forms.SystemInformation.FrameBorderSize.Width; }

1 个答案:

答案 0 :(得分:1)

你不需要这样做。如果使用Grid作为布局容器,则其中的对象将始终展开以占用所有空间。然后,您可以使用边距来排列子面板。使用Top,Center,Bottom,Stretch的Left,Center,Right,Stretch和VerticalAlignment值的各种Horizo​​ntalAlignment值,您可以制作几乎任何可伸缩的布局,而无需检查应用程序是否最大化/最小化等。

您是否想要实现特定的布局,或许我可以发布一个示例?