Reputation: 14493
I'm looking for solution to add snapping/sticky windows functionallity (winamp-like) to existing WPF application. Same thing as it was asked here, just I need it for WPF.
It doesn't have to have docking function, just to snap to border of other windows inside same application and edge of screen (including taskbar) if possible. Preferably open source solution.
Thanks
Upvotes: 27
Views: 15746
Reputation: 46
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.
Upvotes: 2
Reputation: 8766
The WPF Docking Library may provide some of what you are looking for, but I'm unsure if it works on the entire screen or just on your application window.
Upvotes: 0