wpf 自定义Messagebox时,对话框显示不居中问题

在自定义Messagebox(有属性Window.SizeToContent="WidthAndHeight")时,对话框显示不居中,经过尝试,应设置如下:

msgBox.WindowStartupLocation = WindowStartupLocation.Manual;

在显示的时候用以下函数进行移动居中显示:

Win32Api.MoveWindow(Hwnd, Convert.ToInt32( (_parent.ActualWidth - this.ActualWidth) / 2 ),
Convert.ToInt32((_parent.ActualHeight - this.ActualHeight) / 2),
Convert.ToInt32(this.ActualWidth), Convert.ToInt32(this.ActualHeight), false);

posted on 2022-12-15 10:00  wu.g.q  阅读(329)  评论(0编辑  收藏  举报

导航