Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move two WPF windows at once?

Tags:

c#

.net

wpf

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?

like image 320
Jippers Avatar asked Jan 14 '09 23:01

Jippers


2 Answers

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.

like image 183
Jippers Avatar answered Sep 20 '22 22:09

Jippers


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.

like image 43
George Sealy Avatar answered Sep 17 '22 22:09

George Sealy