title: Canvas zooming in WPF using code behind
body: <p>Here the scenario is: </p>
  
  <p><br>
  I have a canvas with different diagrams drawn on it. Now the requirement is to zoom into the canvas using the code behind either using C# or VB. Moreover I need to place the zoom code in some dll so that i can reuse the same set of code through out my application.</p>
  
  <p>Now my question is how to do this....</p>
  
  <p>I have tried the following code pls have a look..</p>
  
  <pre><code>public MainWindow()
  {
      InitializeComponent();
  
      canvas.MouseEnter += new MouseEventHandler(canvas_MouseEnter);
      canvas.MouseWheel += new MouseWheelEventHandler(canvas_MouseWheel);
  }
  
  void canvas_MouseWheel(object sender, MouseWheelEventArgs e)
  {
      double height = canvas.ActualHeight;
      double width = canvas.ActualWidth;
      double zoom = e.Delta;
      height += 2;
      width += 2;
      ScaleTransform sc = new ScaleTransform(width, height);
      canvas.LayoutTransform = sc;
      canvas.UpdateLayout();
  }
  </code></pre>