title: Scroll with mousewheel and zoom image with panning
body: <p>I would like to make a small silverlight app which displays one fairly large image which can be zoomed in by scrolling the mouse and then panned with the mouse.
  it's similar to the function in google maps and i do not want to use deepzoom.</p>
  
  <p>here is what i have at the moment. please keep in mind that this is my first silverlight app:
  this app is just for me to see it's a good way to build in a website. so it's a demo app and therefor has bad variable names. </p>
  
  <p>
          
              
                  
              
          
      </p>
  
  <p>the initial image is 1800px width. </p>
  
  <pre><code>    private void sc_MouseWheel(object sender, MouseWheelEventArgs e)
      {
          var st = (ScaleTransform)plaatje.RenderTransform;
          double zoom = e.Delta &gt; 0 ? .1 : -.1;
          st.ScaleX += zoom;
          st.ScaleY += zoom;
      }
  </code></pre>
  
  <p>this works, but could use some smoothing and it's positioned top left and <em>not</em> centered.</p>
  
  <p>the panning is like this: 
  found it @ <a href="https://stackoverflow.com/questions/741956/wpf-pan-zoom-image">Pan &amp; Zoom Image</a> 
  and converted it to this below to work in silverlight</p>
  
  <pre><code>    Point start;
      Point origin;
      bool captured = false;
  
      private void plaatje_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
      {
          plaatje.CaptureMouse();
          captured = true;
          var tt = (TranslateTransform)((TransformGroup)plaatje.RenderTransform)
              .Children.First(tr =&gt; tr is TranslateTransform);
          start = e.GetPosition(canvasje);
          origin = new Point(tt.X, tt.Y);
      }
  
      private void plaatje_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
      {
          plaatje.ReleaseMouseCapture();
          captured = false;
      }
  
      private void plaatje_MouseMove(object sender, MouseEventArgs e)
      {
          if (!captured) return;
  
          var tt = (TranslateTransform)((TransformGroup)plaatje.RenderTransform).Children.First(tr =&gt; tr is TranslateTransform);
          double xVerschuiving = start.X - e.GetPosition(canvasje).X;
          double yVerschuiving = start.Y - e.GetPosition(canvasje).Y;
          tt.X = origin.X - xVerschuiving;
          tt.Y = origin.Y - yVerschuiving;
      }
  </code></pre>
  
  <p>so the scaling isn't smooth and the panning isn't working, because when i click it, the image disappears.</p>