Hi,
I have a canvas wrapped in a scrollviewer, which I'm using the mousewheel to scale the canvas with.
I'm having problems of finding an easy way of zooming to the exact center of the view in the canvas.
The scrollviewer needs to update the horizontal and vertical offset to stay in place somehow.
I can provide a simple example..
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e) { this.scale.ScaleX += e.Delta * 0.003; this.scale.ScaleY += e.Delta * 0.003; double shift = 0; // ?? scroller.ScrollToHorizontalOffset(scroller.HorizontalOffset + shift); scroller.ScrollToVerticalOffset(scroller.VerticalOffset + shift); } }
<Window x:Class="TestZoom.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="400" Width="600"><ScrollViewer x:Name="scroller" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"><Canvas MouseWheel="Canvas_MouseWheel" Height="450" Width="600"><Canvas.Background><ImageBrush Stretch="Uniform" ImageSource="http://www.imgbase.info/images/safe-wallpapers/photography/miscellaneous/8229_miscellaneous_black-white.jpg" /></Canvas.Background><Canvas.LayoutTransform><ScaleTransform x:Name="scale" /></Canvas.LayoutTransform></Canvas></ScrollViewer></Window>If anyone knows an easy way of calculating the offset's it would be much appreciated.
Niclas