Zoom to mouse point
#2
It is quite easy to implement this behavior by yourself.

You need to disable MouseWheel handling on ZoomPanel and do it yourself from the code with ZoomAndTranslateToCenter method on the ZoomPanel.

The following is a sample of the implementation.

XAML:
Code:
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:zoomPanel="clr-namespace:Ab2d.Controls;assembly=Ab2d.Controls.ZoomPanel"
    Title="Window1" Height="300" Width="300"
    MouseWheel="Window_MouseWheel">
    <Grid>
        <zoomPanel:ZoomPanel Name="ZoomPanel1" IsMouseWheelZoomEnabled="False" ZoomMode="Move">
            <TextBlock Text="12345"/>
        </zoomPanel:ZoomPanel>
    </Grid>
</Window>

Code:
Code:
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            Point mousePosition;
            double zoomFactor;

            if (e.Delta > 0)
                zoomFactor = 1.3;
            else
                zoomFactor = 1 / 1.3;

            mousePosition = e.GetPosition(ZoomPanel1);

            ZoomPanel1.ZoomAndTranslateToCenter(zoomFactor, mousePosition);

            e.Handled = true;
        }

The code simply translates the ZoomPanel to the current mouse position and than applies the zoom factor based on the mouse wheel movement.

Andrej Benedik
  


Messages In This Thread
Zoom to mouse point - by marianokaplan - 11-23-2009, 09:29 PM
RE: Zoom to mouse point - by abenedik - 11-26-2009, 03:10 PM
RE: Zoom to mouse point - by Ronit Well - 11-28-2009, 06:31 AM
RE: Zoom to mouse point - by abenedik - 12-04-2009, 04:35 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)