How to center a WPF app on screen?

前端 未结 8 822
清歌不尽
清歌不尽 2021-01-30 09:53

I want to center my WPF app on startup on the primary screen. I know I have to set myWindow.Left and myWindow.Top, but where do I get the values?

I found System.Wi

8条回答
  •  伪装坚强ぢ
    2021-01-30 10:36

    You don't need to reference the System.Windows.Forms assembly from your application. Instead, you can use System.Windows.SystemParameters.WorkArea. This is equivalent to the System.Windows.Forms.Screen.PrimaryScreen.WorkingArea!

提交回复
热议问题