private void OnMouseMove(object sender, MouseEventArgs e) { var location = e.GetPosition(ImageHostGrid); if (ImageHostGrid.IsMouseCaptured && e.LeftButton == MouseButtonState.Pressed) { if ((Keyboard.Modifiers & ModifierKeys.Alt) > 0) { // Calculate the new phi and theta based on mouse position relative to where the user clicked var dPhi = ((float)(mouseLastLocation.Y - location.Y) / 300); var dTheta = ((float)(mouseLastLocation.X - location.X) / 300); viewModel.CameraRotate(-dTheta, dPhi); } } else if (ImageHostGrid.IsMouseCaptured && e.MiddleButton == MouseButtonState.Pressed) { if ((Keyboard.Modifiers & ModifierKeys.Alt) > 0) { var dx = ((float)(mouseLastLocation.X - location.X)); var dy = ((float)(mouseLastLocation.Y - location.Y)); viewModel.CameraPan(-dx, dy); } } mouseLastLocation = location; }