views:

52

answers:

1

Greetings, I would like to have child window docked next to my parent window. If I move parent window, child window should be also moved. This image should explain what i would like to achieve. Can someone help me please. I'm writing in WPF.

Does anybody has an idea how to do this?

A: 

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.

Ray Burns