You can simply use the Window.Left and Window.Top properties. Read them from the main window and assign values (plus 20 pixels or something else) to the AboutBox before by calling the ShowDialog() method.
AboutBox dialog = new AboutBox(); dialog.Top = mainWindow.Top + 20;
To focus on it, you can also just use the WindowStartupLocation property. Set it to WindowStartupLocation.CenterOwner
AboutBox dialog = new AboutBox(); dialog.Owner = Application.Current.MainWindow; // We must also set the owner for this to work. dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
If you want it to be centered horizontally, but not vertically (i.e. a fixed vertical arrangement), you will need to do this in the EventHandler after loading the AboutBox, because you will need to calculate the horizontal position depending on the width ofBox. and this is known only after it has been downloaded.
protected override void OnInitialized(...) { this.Left = this.Owner.Left + (this.Owner.Width - this.ActualWidth) / 2; this.Top = this.Owner.Top + 20; }
gehho.
gehho Mar 15 '10 at 11:28 2010-03-15 11:28
source share