Handle Window.LocationChanged events and Window.LocationChanged events in the main window. When one of these events occurs, calculate the new location for the child window.
Here is an idea:
var mainWindow = ...; var childWindow = ...; var handler = new EventHandler(() => { childWindow.Top = mainWindow.Top; childWindow.Left = mainWindow.Left + mainWindow.Width; }); mainWindow.LocationChanged += handler; mainWindow.SizeChanged += handler;
You may also need code that removes the handler from both events when the child window no longer needs to dock or no longer works.
source share