开发者

How to reset height and re-center a WPF form at runtime?

I try to reset the height of my form in its Loaded event but the position of the form is not centered screen anymore.

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?
}

Please help if you know how to. Great thanks!

Nam.

[Edit]

I re-note the answer here thanks to xandy help.

var screenHeight += System.Windows.SystemParameters.PrimaryScreenHeight;
window.Top = (screenHeight - manualHeight) / 2;


manually set the window y position to:

window.Top = (screenHeight - manualHeight) / 2;

where you can have the screenHeight here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜