As soon as the application starts, I want my WPF window to automatically snap to the right edge of the screen. Is there any way to do this? I also want to keep my size. Thus, unlike the snap behavior that occurs when you drag a window to the edge of the screen, causing the window to resize either on part of the screen or on the entire screen, I want my window to simply snap to the edge at a specific location by default, or then dragged by the user to a specific location, without resizing. I still want to keep the user's ability to drag the window from the edge.
Is there something similar already implemented or do I need to create my own behavior pattern? I tried numerous combinations of search keywords, but could not find anything similar to what I was doing. Some of the search queries included disabling the snap or providing the snap, but nothing was described above.
EDIT:
I could not find a ready-made solution, so I wrote my own. This solution is based on BenVlodgi's suggestions, so I thank him for his help. This is a very crude implementation and still requires a lot of polishing and improvement of the code methods, but it works, and it is a good base for those who want to try this. It is incredibly simple and works great with WPF. The only limitation of this implementation is that I have not yet tried to get it to work with two screens, but it is incredibly simple (I just won’t have time for this, and I don’t need this functionality at the moment), So here is the code, and I hope he helps someone:
public partial class MainWindow : Window {
Make sure your window has the following:
MouseDown="Window_MouseDown" MouseUp="Window_MouseUp" WindowStartupLocation="Manual" Loaded="Window_Loaded"
Also, this doesn’t work very well with native Windows components in the window, such as the top bar, so I turn off the style and create my own (which is actually good for me, since I don’t want windows to style this):
WindowStyle="None"
source share