4

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. The image below should explain what i would like to achieve:
http://img689.imageshack.us/img689/1305/childdockedwindow.jpg
Can someone help me please. I'm writing in WPF. Does anybody have an idea on how to do this?

Barn Monkey
  • 245
  • 3
  • 11
niao
  • 4,972
  • 19
  • 66
  • 114

1 Answers1

1

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
  • 62,163
  • 12
  • 140
  • 141