private void OnMouseMove(object sender, MouseEventArgs e) { if (!_isMouseButtonDown) { return; } var currentDpiScaleFactor = SystemHelper.GetCurrentDPIScaleFactor(); var position = e.GetPosition(this); var screen = PointToScreen(position); var x = _mouseDownPosition.X - position.X; var y = _mouseDownPosition.Y - position.Y; if (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) > 1) { var actualWidth = _mouseDownPosition.X; if (_mouseDownPosition.X <= 0) { actualWidth = 0; } else if (_mouseDownPosition.X >= ActualWidth) { actualWidth = _widthBeforeMaximize; } if (WindowState == WindowState.Maximized) { ToggleWindowState(); Top = (screen.Y - position.Y) / currentDpiScaleFactor; Left = (screen.X - actualWidth) / currentDpiScaleFactor; CaptureMouse(); } _isManualDrag = true; Top = (screen.Y - _mouseDownPosition.Y) / currentDpiScaleFactor; Left = (screen.X - actualWidth) / currentDpiScaleFactor; } }