This library helps creating window applications where the windows can both stick to screen borders and to each other.
The code originates from the Codeproject article Sticky Windows - How to make your (top-level) forms to stick one to the other or to the screen by Corneliu Tusnea. He never published a NuGet package, so I asked for his permission to both create a repository at GiutHub and publish it as a NuGet package.
Stable | Pre-release | |
---|---|---|
AppVeyor | ||
StickyWindows | ||
StickyWindows.Wpf |
Actually there are two libraries published: one is for WinForms applications, and the other one for WPF applications. The latter bases on the WinForms package though. but this shouldn't be an issue as that the WinForms library is part of the .NET framework and as such is always available.
For WinForms application, use the StickyWindow package.
In the constructor of your form add this line:
new StickyWindows.StickyWindow(this);
If you want to deviate from the default settings, StickyWindow
provides following
boolean properties (which are all true
by default:
StickOnMove
Allows the form to try to stick when the form is moved.StickOnResize
Allows the form to try to stick when the form is resized.StickToOther
Allows the form to try to stick to other stick-able forms.StickToScreen
Allows the form to try to stick to the screen margins.
For WinForms application, use the StickyWindow.WPF package.
You have two options to make your windows "sticky":
-
Subscribe to your window's
Loaded
event and call the extension methodCreateStickyWindow
in the handler:_stickyWindow = this.CreateStickyWindow();
-
Use the
StickyWindowBehavior
in your XAML code (which I think is more elegant than option 1):<Window x:Class="WpfTest.Window2" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:wpf="clr-namespace:StickyWindows.WPF;assembly=StickyWindows.WPF" ...> <i:Interaction.Behaviors> <wpf:StickyWindowBehavior /> </i:Interaction.Behaviors> ... </Window>
Both options support the same properties as the WinForms implementation.
Please note that StickyWindows.WPF requires System.Windows.Interactivity, which is neither part of the library nor a dependency of the NuGet package. The point is, there's no official NuGet package for System.Windows.Interactivity by Microsoft. I decided against delivering this library as part of StickyWindows.WPF as it may conflict with different versions in other libraries you may be using potentially.
- Fixed the MaximumSize and MinimumSize issue reported in #5 (Thanks to @lucky3)
- Added SourceLink support
- Fixed strange margin when running on Windows 10 (#1)
- Inital Release