Reputation: 125
I used this:
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
to position the first window (W1) in the middle of the screen.
With a button click, I want to place a new window (W2) beside the first one.
Image showing how it should be (W=Window)
Upvotes: 1
Views: 955
Reputation: 1138
The following code should do the job :
private void Button_Click(object sender, RoutedEventArgs e)
{
Window2 w2 = new Window2();
w2.WindowStartupLocation = WindowStartupLocation.Manual;
w2.Left = this.Left + this.Width;
w2.Top = this.Top + (this.Height - w2.Height) / 2;
w2.Show();
}
If you want the second window to track changes to the size and position of the first then you'd need to handle the appropriate events and correct the position of the second window using similar logic to the above.
Upvotes: 2