如何在运行时重置高度并重新居中WPF表单?
我试图在已加载事件中重置窗体的高度,但窗体的位置不再位于屏幕中央如何在运行时重置高度并重新居中WPF表单?,wpf,runtime,height,code-behind,Wpf,Runtime,Height,Code Behind,我试图在已加载事件中重置窗体的高度,但窗体的位置不再位于屏幕中央 private void Window_Loaded(object sender, RoutedEventArgs e) { var manualHeight = 0 + this.MessageRow.ActualHeight + this.ButtonsRow.ActualHeight ; this.Height = manualHeight; //What t
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var manualHeight = 0
+ this.MessageRow.ActualHeight
+ this.ButtonsRow.ActualHeight
;
this.Height = manualHeight;
//What to do to re-center the form?
}
如果你知道怎么做,请帮忙。非常感谢
南
[编辑]
多亏了xandy的帮助,我在这里重新记下了答案
手动将窗口y位置设置为: 窗口顶部=屏幕高度-手动高度/2 在那里你可以有屏幕高度
var screenHeight += System.Windows.SystemParameters.PrimaryScreenHeight;
window.Top = (screenHeight - manualHeight) / 2;