Draggable WPF window with no border Draggable WPF window with no border wpf wpf

Draggable WPF window with no border


Use the tunneled MouseDown event, i.e, the PreviewMouseLeftButtonDown event of the Window. This will ensure that the event occurs both on the Window and its child controls:

this.PreviewMouseLeftButtonDown += (s, e) => DragMove();

You can also add an event to the TextBox manually:

textBox.MouseDown += (s, e) => DragMove();

But:

Doing what you want has its inherent problems. It will not let you select text in the TextBox. There is a workaround - use a Key + MouseDrag input like this:

bool isKeyPressed = false;public MainWindow(){    InitializeComponent();    this.PreviewKeyDown += (s1, e1) => { if (e1.Key == Key.LeftCtrl) isKeyPressed = true; };    this.PreviewKeyUp += (s2, e2) => { if (e2.Key == Key.LeftCtrl) isKeyPressed = false; };    this.PreviewMouseLeftButtonDown += (s, e) => { if (isKeyPressed) DragMove(); };}