Move a borderless window in wpf


It's super simple, here:

private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
Harry Boy
Author by

Harry Boy

Updated on November 25, 2022


  • Harry Boy
    Harry Boy about 1 month

    In my C# WinForms app I have a main window that has its default controls hidden.

    So to allow me to move it around I added the following to the main window:

    private const int WM_NCHITTEST = 0x84;
    private const int HTCLIENT = 0x1;
    private const int HTCAPTION = 0x2;
    private const int WM_NCLBUTTONDBLCLK = 0x00A3;
    protected override void WndProc(ref Message message)
        if (message.Msg == WM_NCLBUTTONDBLCLK)
            message.Result = IntPtr.Zero;
        base.WndProc(ref message);
        //Allow window to move
        if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
            message.Result = (IntPtr)HTCAPTION;

    I have a WPF App where I have also hidden the default controls and I want to do the same. I see that the main window is derived from a 'Window' so the above code does not work. How do I do this in WPF?