Here is the Solution you actually asked for:
Let's say we have 2 Xaml windows named MainWindow and Window2:
MainWindow:
Window2 windows2;
public void RealodPos()
{
if (windows2 == null) { windows2 = new Window2(this); this.Top = 300; }
windows2.Top = this.Top;
windows2.Left = this.Width + this.Left - 15;
windows2.Show();
}
private void Window_Activated(object sender, EventArgs e)
{
RealodPos();
}
private void SizeChenged(object sender, SizeChangedEventArgs e)
{
RealodPos();
}
private void LocationChange(object sender, EventArgs e)
{
RealodPos();
}
Window2:
public partial class Window2 : Window
{
MainWindow Firstwin;
public Window2(MainWindow FirstWindow)
{
InitializeComponent();
Firstwin = FirstWindow;
}
void RealodPos()
{
this.Top = Firstwin.Top;
this.Left = Firstwin.Width + Firstwin.Left - 15;
}
private void Window_Activated(object sender, EventArgs e)
{
RealodPos();
}
private void Window_LocationChanged(object sender, EventArgs e)
{
RealodPos();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
RealodPos();
}
}
My suggestion as a Software engineer:
Hint1: I don't know where you will use this but it's better to convert it to a reusable component that is not hardcoded with only 2 windows.
Hint2: Convert the
public Window2(MainWindow FirstWindow)
's MainWindow argument to a Window class formant to have a more flexible pointer for reusing it in the other applications.
Here is my suggested Solution for pro-WPF developers:
instead of doing this in that way you can make your own customized windows on XAML and use UserControls instead of other windows that you need.
Thanks for reading, please ask me if you want anything else or if you need the code as a project file.