/// <summary> /// Zoom feature implementation. /// </summary> private void DropZone_MouseWheel(object sender, MouseWheelEventArgs args) { if (!this.HasEffectiveKeyboardFocus) { return; } var scaleTransform = (ScaleTransform)((TransformGroup)VideoControl.RenderTransform).Children.First(tr => tr is ScaleTransform); var zoom = args.Delta > 0 ? ZoomRatio : -ZoomRatio; var relativePointCache = VideoControl.TranslatePoint(new Point(0, 0), DropZone); var translateTransform = (TranslateTransform)((TransformGroup)VideoControl.RenderTransform).Children.First(tr => tr is TranslateTransform); var height = VideoControl.ActualHeight * scaleTransform.ScaleY; var width = VideoControl.ActualWidth * scaleTransform.ScaleX; if (width + zoom < this.ActualWidth && height + zoom < this.ActualHeight && zoom < 0) { translateTransform.X = 0; translateTransform.Y = 0; return; } if (scaleTransform.ScaleX + zoom > ZoomMinTreshold && scaleTransform.ScaleX + zoom < ZoomMaxTreshold && scaleTransform.ScaleY + zoom > ZoomMinTreshold && scaleTransform.ScaleY + zoom < ZoomMaxTreshold) { scaleTransform.ScaleX += zoom; scaleTransform.ScaleY += zoom; } if (zoom > 0) { return; } height = VideoControl.ActualHeight * scaleTransform.ScaleY; width = VideoControl.ActualWidth * scaleTransform.ScaleX; var relativePoint = VideoControl.TransformToVisual(DropZone).Transform(new Point(0, 0)); var mathRelativePositionY = Math.Round(relativePoint.Y - relativePointCache.Y, MidpointRounding.AwayFromZero); var mathRelativePositionX = Math.Round(relativePoint.X - relativePointCache.X, MidpointRounding.AwayFromZero); var mathTranslateY = Math.Round(translateTransform.Y, MidpointRounding.AwayFromZero); var mathTranslateX = Math.Round(translateTransform.X, MidpointRounding.AwayFromZero); if (height < DropZone.ActualHeight) { translateTransform.Y = 0; } else if (relativePoint.Y > 0) { translateTransform.Y = mathTranslateY - mathRelativePositionY; } else if (relativePoint.Y + height < DropZone.ActualHeight) { translateTransform.Y = mathTranslateY + mathRelativePositionY; } if (width < DropZone.ActualWidth) { translateTransform.X = 0; } else if (relativePoint.X > 0) { translateTransform.X = mathTranslateX - mathRelativePositionX; } else if (relativePoint.X + width < DropZone.ActualWidth) { translateTransform.X = mathTranslateX + mathRelativePositionX; } }