How to center a WPF app on screen?

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

    What about the SystemParameters class in PresentationFramework? It has a WorkArea property that seems to be what you are looking for.

    But, why won't setting the Window.WindowStartupLocation work? CenterScreen is one of the enum values. Do you have to tweak the centering?

提交回复
热议问题