Perhaps because you did not set the owner:
this.Owner = App.MainWindow; // for example
The way I do it and it perfectly centers the window.
To extend to what Will Eddins commented on, you can create an overload method for ShowDialog () or Show () in your window:
public void ShowDialog(Window owner) { this.Owner = owner; this.ShowDialog(); } public void Show(Window owner) { this.Owner = owner; this.Show(); }
Or reload the constructor:
public MyWindow(Window owner) : this() { this.Owner = owner; }
Carlo Aug 10 '10 at 19:57 2010-08-10 19:57
source share