Exemplo n.º 1
0
        private void ZoomControl_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            double deltaZoom = GetZoomDelta(e.Delta);
            double width     = zoomControl.ActualWidth * deltaZoom;
            double height    = zoomControl.ActualHeight * deltaZoom;

            Point  cursorPosition      = e.GetPosition(zoomControl);
            double currentRelativeLeft = cursorPosition.X / zoomControl.ActualWidth;
            double currentRelativeTop  = cursorPosition.Y / zoomControl.ActualHeight;

            var topLeftCorner = new Point(
                cursorPosition.X - width * currentRelativeLeft,
                cursorPosition.Y - height * currentRelativeTop);

            var newSize = new Size(width, height);
            var zoomTo  = new Rect(topLeftCorner, newSize);

            zoomControl.ZoomTo(zoomTo);
            e.Handled = true;
        }