How to center a WPF app on screen?

前端 未结 8 832
清歌不尽
清歌不尽 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:22

    There is no WPF equivalent. System.Windows.Forms.Screen is still part of the .NET framework and can be used from WPF though.

    See this question for more details, but you can use the calls relating to screens by using the WindowInteropHelper class to wrap your WPF control.

提交回复
热议问题