Handle the Window.LocationChanged
events and Window.SizeChanged
events on the main window. When either of these events fires, compute the new location for the child window.
Here is the 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 handler
from both events when the child window no longer needs to be docked or is no longer shon.