wpf 窗口设置位置后,先在屏幕中央显示一下后,才在设置的位置显示窗口。解决方案如下:
不要在窗体load事件中设置窗体显示位置,在构造函数中设置显示位置即可。
public MainWindow()
{
InitializeComponent();
WindowNormal();
}
private void WindowNormal()
{
try
{
double screenWidth = System.Windows.SystemParameters.WorkArea.Width;
double screenHeight = System.Windows.SystemParameters.WorkArea.Height;
this.Height = screenHeight;
this.Width = screenWidth / 3;
this.Top = 0;
this.Left = screenWidth * 2 / 3;
//this.Topmost = true;
this.Visibility=Visibility.Visible;
}
catch (Exception ex)
{
LOG.Error(ex.ToString());
}
}