Use the tunneled MouseDown event, i.e. PreviewMouseLeftButtonDown window event. This will ensure that the event occurs both in the window and in its child controls:
this.PreviewMouseLeftButtonDown += (s, e) => DragMove();
You can also add an event to the text box manually:
textBox.MouseDown += (s, e) => DragMove();
But
Doing what you want has its inherent problems. This will not allow you to select text in a TextBox. There is a workaround - use the Key + MouseDrag as follows:
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(); }; }
source share