![](/img/trans.png)
[英]How to dynamically change grid rows and columns according to window size in WPF
[英]How to change size of WPF Window dynamically?
假设我们展示了一些WPF窗口,我们必须在底部显示一些额外的面板。
我想要做的是增加WPF窗口大小并再次居中。
任何线索或样品?
您可以通过编程方式更改窗口的大小和位置,只需为大小设置适当的宽度和高度值,为位置设置顶部和左侧。 但它更容易。
点击此页面即可获得
<Window x:Class="SizingTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1"
Width="Auto" Height="Auto" SizeToContent="WidthAndHeight">
如果要以特定大小调整大小,可以执行以下操作:
如果要调整主窗口的大小,只需编写以下代码即可。
Application.Current.MainWindow.Height = 420;
如果要调整主窗口以外的新窗口,只需在新窗口的.cs文件中编写以下代码即可。
Application.Current.MainWindow = this;
Application.Current.MainWindow.Width = 420;
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.