title: WPF zoom canvas and maintain scroll position
body: <p>I have a Canvas element, contained within a ScrollViewer, which I'm zooming using ScaleTransform. However, I want to be able to keep the scroll position of the viewer focused on the same part of the canvas after the zoom operation has finished. Currently when I zoom the canvas the scroll position of the viewer stays where it was and the place the user was viewing is lost.</p>
  
  <p>I'm still learning WPF, and I've been going backwards and forwards a bit on this, but I can't figure out a nice XAML based way to accomplish what I want. Any help in this matter would be greatly appreciated and would aid me in my learning process. </p>
  
  <p>Here is the kind of code I'm using...</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;ScrollViewer Name="TrackScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"&gt;
          &lt;Canvas Width="2560" Height="2560" Name="TrackCanvas"&gt;
              &lt;Canvas.LayoutTransform&gt;
                  &lt;ScaleTransform ScaleX="{Binding ElementName=ZoomSlider, Path=Value}" 
                                  ScaleY="{Binding ElementName=ZoomSlider, Path=Value}"/&gt;
              &lt;/Canvas.LayoutTransform&gt;
  
              &lt;!-- Some complex geometry describing a motor racing circuit --&gt;
  
          &lt;/Canvas&gt;
      &lt;/ScrollViewer&gt;
      &lt;StackPanel Orientation="Horizontal" Margin="8" VerticalAlignment="Top" HorizontalAlignment="Left"&gt;
          &lt;Slider Name="ZoomSlider" Width="80" Minimum="0.1" Maximum="10" Value="1"/&gt;
          &lt;TextBlock Margin="4,0,0,0" VerticalAlignment="Center" Text="{Binding ElementName=ZoomSlider, Path=Value, StringFormat=F1}"/&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>