How do I move a wpf window into a negative top value?

If I use dragMove the wpf window will not move to a location where the y value is negative. I can however set the windows top value to a negative value. Is there a simple way to enable dragMove to allow the top of the window to be moved above the displays 0 position?


It seems that this is the default window's handling of moveWindow. Verified with a call to SendMessage( hwnd, WM_SYSCOMMAND, SC_MOVE, null);


As I found, the window will move to "negative" location, but will then jump back. To prevent this you could do something like:

public partial class Window1: Window {

    public Window1() {

    private void Window_MouseDown(object sender, MouseButtonEventArgs e) {

    public struct WINDOWPOS {
        public IntPtr hwnd;
        public IntPtr hwndInsertAfter;
        public int x;
        public int y;
        public int cx;
        public int cy;
        public UInt32 flags;

    private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
        switch(msg) {
            case 0x46://WM_WINDOWPOSCHANGING
                if(Mouse.LeftButton != MouseButtonState.Pressed) {
                    WINDOWPOS wp = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS));
                    wp.flags = wp.flags | 2; //SWP_NOMOVE
                    Marshal.StructureToPtr(wp, lParam, false);
        return IntPtr.Zero;

    private void Window_Loaded(object sender, RoutedEventArgs e) {
        HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
        source.AddHook(new HwndSourceHook(WndProc));

Handling WM_WINDOWPOSCHANGING this way will prevent any movement of the window unless left mouse button is pressed. This includes maximizing the window and programmatic change of window position as well, so you'll have to adapt the code if you need another behavior.

Need Your Help

Sort not sorting numbers correctly in R

r sorting order

I have data that looks like this:

how implement a folder, subfolder in a Database

php mysql sql recursion relational-database

I'm having a problem with logic programming, but I think that could be another solution much easier to do this in a SQL command, however, let's go to the problem.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.