11

I'm wondering about the best way to get information about the current position and width/height of the MainWindow. I want to keep a child window inside the main window so I want to check the coordinates of the MainWindows borders during the move function of the child window. I could only find the Window.LocationChanged event but it doesn't solve my problem in a satisfying way. Are there better options?

Unfixable
  • 440
  • 1
  • 7
  • 20

2 Answers2

34

You can access the position of the main window all over your code via Application.Current.MainWindow.Left and Application.Current.MainWindow.Top, respectively. Hope this will help.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Dudemeister
  • 537
  • 4
  • 9
  • 2
    this only works if you only have one window or it is the main window of the application. I found a better solution [here](http://stackoverflow.com/a/8056464/937093) – Steffen Winkler Nov 06 '15 at 10:19
4

But, you should check "WindowState". In "Maximized" state properties "Left" and "Top" keep the values of the window in it's normal state. Window position in "Maximized" state discribes here: How can I find the position of a maximized window?

Community
  • 1
  • 1
no.Oby
  • 107
  • 8