My main window has spawned a child window that's positioned on top to look like part of the main. I would like to move the child window in sync with the main but I'm not sure how.
My main window has my own title bar which event MouseLeftButtonDown calls this function:
public void DragWindow(object sender, MouseButtonEventArgs args)
{
DragMove();
UpdateChildWindowPosition();
}
This results in DragMove() executing on the main window moves the main window alone as I drag the title bar. UpdateChildWindowPosition() is not executed until I release the mouse at which it reads some element coordinates and sets the child window position - you see the child window snap to the location which is not desired.
How can I have the child window move in sync with the main window?
AH HAH!
My Main window has an event LocationChanged which I've tied to my UpdateChildWindowPosition(). LocationChange fires when (duh) the location changes so it's continuously firing as I move the window when DragMove() is being executed in my DragWindow posted above.
You can use the window's Left and Top properties to place the secondary window. Here's a rough bit of code as an example:
In the MainWindow code:
mDebugWindow.Left = this.Left + this.ActualWidth;
mDebugWindow.Top = this.Top;
In this case mDebugWindow is my child window. This code tells it to sit on the right hand side of the main window, with the tops of the windows aligned.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With