Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在运行时重置高度并重新居中WPF表单?_Wpf_Runtime_Height_Code Behind - Fatal编程技术网

如何在运行时重置高度并重新居中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;