<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>CTRLALT313373.com - Deep Zoom</title>
    <link>http://weblog.ctrlalt313373.com/</link>
    <description>.Net Wanderings</description>
    <language>en-us</language>
    <copyright>David A. Osborn</copyright>
    <lastBuildDate>Sun, 07 Dec 2008 17:21:38 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>davido@ctrlalt313373.com</managingEditor>
    <webMaster>davido@ctrlalt313373.com</webMaster>
    <item>
      <trackback:ping>http://weblog.ctrlalt313373.com/Trackback.aspx?guid=2da2f1cf-b0be-487d-b5b4-4df5aa379407</trackback:ping>
      <pingback:server>http://weblog.ctrlalt313373.com/pingback.aspx</pingback:server>
      <pingback:target>http://weblog.ctrlalt313373.com/PermaLink,guid,2da2f1cf-b0be-487d-b5b4-4df5aa379407.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://weblog.ctrlalt313373.com/CommentView,guid,2da2f1cf-b0be-487d-b5b4-4df5aa379407.aspx</wfw:comment>
      <wfw:commentRss>http://weblog.ctrlalt313373.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2da2f1cf-b0be-487d-b5b4-4df5aa379407</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
With the release of Silverlight 2.0 also came the functionality of Deep Zoom. Deep
Zoom optimizes the viewing of large images in a smooth manner by partitioning an image
into tiles and levels of resolution of the original image. Using this method allows
for the browser to download a lower resolution image for a faster download speed and
then only grab the higher resolution image if the user zooms in. When the user does
zoom in the tile that represents that section of the higher resolution image is download
to the browser again saving the viewer download time and enhancing the user experience. 
</p>
        <p>
In order to begin working with Deep Zoom the first thing we need to do is prepare
an image for Deep Zoom by creating tiles out of the image of different resolutions.
This would be a bit cumbersome to do by hand so luckily Microsoft has provided us
with the Deep Zoom Composer which you can <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.microsoft.com%2Fdownloads%2Fdetails.aspx%3Ffamilyid%3D457b17b7-52bf-4bda-87a3-fa8a4673f8bf&amp;ei=igM8SbX_MojaM8-R2a8F&amp;usg=AFQjCNE5i8Ndl2AZGRxmQ8seQB1MZawSVA&amp;sig2=3w05HjQyqEhCJaSEFkrewA">download</a> for
free. This allows us to create the Deep Zoom images and even allows us to create a
collage of image in Deep Zoom. We will be doing the latter, using the numerous amount
of photos that I took while traveling through Europe for the month of September. 
</p>
        <p>
The first thing we need to do is create a new project in Deep Zoom Composer. Do this
by running the Deep Zoom Composer and selecting new project. After doing this you
will see three tabs along the top – Import, Compose, and Export. If you are not already
on the Import tab, select it, and then we need to add the images that we want to work
with. In my case I will be adding in all my pictures from Rome. Click the Add Image…
button on the right and select the images that you want to add. Remember that you
can select multiple images at once to get your images imported in faster. 
</p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa1.png" alt="" />
        </p>
        <p>
        </p>
        <p>
Once the images are imported we then switch over to the Compose tab. The tab allows
you to create how the final image will look in your Silverlight Application. Select
your imported images from the side and place them on the canvas how you would like
them to appear. You can zoom in and out on the canvas and place your photos at different
depths, even embedding them within each other. For instance I have an image of the
Coliseum from the distance with a sign that is on the side of it. I then have a closer
image of that sign as another picture. The Deep Zoom composer allows me to embed the
more detailed image of the sign into the image of the Coliseum. 
</p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa2.png" alt="" />
        </p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa3.png" alt="" />
        </p>
        <p>
        </p>
        <p>
In the composer you also have the ability to associate tags with the images. I have
associated various tags with all my images. Through the composer you can only apply
one string as a tag, so I have used this field to enter multiple "tags" separated
by commas. In a future tutorial I will demonstrate how to create a tag filter to filter
down images shown in the MultiScaleImage. 
</p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa4.png" alt="" />
        </p>
        <p>
        </p>
        <p>
Once we have exported the images from Deep Zoom Composer it is now time to get our
hands dirty in Visual Studio 2008. In order to work with Silverlight 2.0 applications
you are going to need 3 things, Visual Studio 2008 SP1, the Silverlight SDK, and the
Silverlight tools for Visual Studio 2008. Fire up vs2008, go to File-&gt;New-&gt;Project
and under Visual C# (or if you prefer you can select VB) select Silverlight. Then
select Silverlight Application on the right, name your solution, and select where
you want to save it. 
</p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa5.png" alt="" />
        </p>
        <p>
        </p>
        <p>
Next a window will appear that will ask you if you want to add a new ASP.NET web project
to the solution or generate a test page at build time. Every Silverlight application
needs to be hosted inside a web application so we will let Visual Studio add a project
to our solution for this purpose. 
</p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa6.png" alt="" />
        </p>
        <p>
        </p>
        <p>
If you now look in the Solution Explorer you will see that we have an empty Silverlight
Application called DeepZoomExample2 and a ASP.NET web project called DeepZoomExample2.Web.
The web project has two pages that were created for us, an aspx page and a html page
that hosts our Silverlight Application. 
</p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa7.png" alt="" />
        </p>
        <p>
        </p>
        <p>
Next we need to add our exported images to the web project. Add a new folder under
the ClientBin folder on the Web Project and call it GeneratedImages. The ClientBin
folder is where the compiled .xap file from your Silverlight will live so this is
the easiest place to put our exported files. Now go into your exported folder from
the Deep Zoom Composer and open up the generated images folder and copy the dzc_output_files
folder, and the dzc_output_images folder along with the three files, dzc_output.xml,
Metadata.xml, SparseImageSceneGraph.xml into the new GeneratedImages folder that you
created in your web project. If you used a lot of images this may take some time to
copy. Your Solution Explorer should now look like the following image. 
</p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa8.png" alt="" />
        </p>
        <p>
        </p>
        <p>
Now it's time to start writing some code. First we add a MultiScaleImage to the Page.xaml
file. The Source property will be directed at the dzc_output.zml files that we copied
into our GeneratedImages folder. 
</p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">&lt;</span>
            <span style="color:#a31515">Grid</span>
            <span style="color:blue">
            </span>
            <span style="color:red">x:Name</span>
            <span style="color:blue">=</span>"<span style="color:blue">LayoutRoot</span>"<span style="color:blue"></span><span style="color:red">Background</span><span style="color:blue">=</span>"<span style="color:blue">White</span>"<span style="color:blue">&gt; </span></span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue"> &lt;</span>
            <span style="color:#a31515">MultiScaleImage</span>
            <span style="color:blue">
            </span>
            <span style="color:red">x:Name</span>
            <span style="color:blue">=</span>"<span style="color:blue">msi</span>"<span style="color:blue"></span><span style="color:red">ViewportWidth</span><span style="color:blue">=</span>"<span style="color:blue">1.0</span>"<span style="color:blue"></span><span style="color:red">Source</span><span style="color:blue">=</span>"<span style="color:blue">/GeneratedImages/dzc_output.xml</span>"<span style="color:blue"> /&gt; </span></span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">&lt;/</span>
            <span style="color:#a31515">Grid</span>
            <span style="color:blue">&gt; </span>
          </span>
        </p>
        <p>
        </p>
        <p>
This is all we need to do to get the basic images on the screen, but that isn't very
exciting so lets wire up some zooming using the mouse button. In the Page.xaml.cs
file we need to add a few variables to store some information: 
</p>
        <p>
        </p>
        <p>
          <span style="color:green; font-family:Courier New; font-size:10pt">//This variable
is used to know if the user has just click the left button or has clicked and dragged </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">bool</span> mouseIsDragging
= <span style="color:blue">false</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Indicates
if left mouse button is down </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">bool</span> mouseButtonPressed
= <span style="color:blue">false</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Starting
Point of the Drag </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:#2b91af">Point</span> dragOffset; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Get
Current ViewPort position of MSI </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:#2b91af">Point</span> currentPosition; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Last
Position of Mouse </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:#2b91af">Point</span> lastMousePos
= <span style="color:blue">new</span><span style="color:#2b91af">Point</span>(); </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">public</span>
            <span style="color:blue">double</span> ZoomFactor </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">get</span>; <span style="color:blue">set</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
We then have three mouse events that we need to handle, LeftMouseButton down, LeftMouseButton
up, and Mouse Move. Then we need to handle the actual zoom. 
</p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handles
Left Mouse button down event </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> LeftMouseButtonDownHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Indicate
that the button is down </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseButtonPressed = <span style="color:blue">true</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Reset
Dragging </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseIsDragging = <span style="color:blue">false</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Set
Starting point of the drag if the user start dragging </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> dragOffset = e.GetPosition(<span style="color:blue">this</span>); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> currentPosition = msi.ViewportOrigin; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
In the left mouse button down even, we first set the indicator that the button is
pressed. We then reset the dragging indicator, get the current position of the mouse,
and finally get the current position of the MultiScaleImage. 
</p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handles
Left Mouse button up event </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> LeftMouseButtonUpHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Change
flag to mouse button no longer pressed </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseButtonPressed = <span style="color:blue">false</span>; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//If
the user wasn't dragging then we do zooming </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">if</span>(!mouseIsDragging) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Check
if shift was pressed. If so we zoom out, otherwise we zoom in </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">bool</span> shiftDown
= (<span style="color:#2b91af">Keyboard</span>.Modifiers &amp; <span style="color:#2b91af">ModifierKeys</span>.Shift)
== <span style="color:#2b91af">ModifierKeys</span>.Shift; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> ZoomFactor = 2.0; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">if</span> (shiftDown)
ZoomFactor = 0.5; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> Zoom(ZoomFactor, <span style="color:blue">this</span>.lastMousePos); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
When the left mouse button is lifted we change the flag that indicates that the left
mouse button is down and if the user was not dragging. We then check to see if shift
was pressed. If shift was not pressed we zoom in by a factor of 2, but if shift was
pressed we zoom out by a factor of .5. We then call our zoom function (which we have
yet to create) with the zoom factor and the last point the mouse was at. 
</p>
        <p>
        </p>
        <p style="margin-left: 36pt">
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray"> ///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handlers
the moving of the mouse </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> MouseMoveHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.lastMousePos
= e.GetPosition(<span style="color:blue">this</span>.msi); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
With the mouse move function all we need to do is capture the position that the mouse
is at. Finally in the below Zoom function that is called from the LeftMouseButtonUpHandler,
we do the actual zooming. 
</p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">public</span>
            <span style="color:blue">void</span> Zoom(<span style="color:blue">double</span> zoom, <span style="color:#2b91af">Point</span> pointToZoom) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:#2b91af">Point</span> logicalPoint
= <span style="color:blue">this</span>.msi.ElementToLogicalPoint(pointToZoom); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.ZoomAboutLogicalPoint(zoom,
logicalPoint.X, logicalPoint.Y); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
As you can see above we have to translate the mouse pointer relative to our MultiScaleImage
and then we use the ZoomAboutLogicalPoint method to handle the zooming for us. The
last thing we need to do is wire up the events to the MultiScaleImage control in the
Page constructor which will look like the following: 
</p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">public</span> Page() </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> InitializeComponent(); </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Wire
up events </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeftButtonDown
+= LeftMouseButtonDownHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeftButtonUp
+= LeftMouseButtonUpHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseMove
+= MouseMoveHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
If you now run the application you will get the layout of all images on your screen
as seen in the first picture below, and if I click on the picture of St. Peter's Square
in the center of the image the MultiScaleImage control will zoom in on that particular
image as seen in the second picture below. Holding down the shift key while clicking
will zoom the MultiScaleImage back out. 
</p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa9.png" alt="" />
        </p>
        <p>
        </p>
        <p>
          <img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa10.png" alt="" />
        </p>
        <p>
In order to enable panning we need to augment a few functions that we have already
created. Obviously we need to modify the MouseMoveHandler. Initially all this event
was doing was updating the mouse position so that when we zoomed in or out we knew
where the mouse was pointing. Now we are going to have it check to see if the mouse
button is down to indicate that dragging is occurring. Also if the mouse is dragging
we need to update the position so that the MultiScaleImage is centered on to where
the mouse is dragging. Our new MouseMoveHandler appears below. 
</p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handlers
the moving of the mouse </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> MouseMoveHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">if</span>(mouseButtonPressed) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseIsDragging = <span style="color:blue">true</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.lastMousePos
= e.GetPosition(<span style="color:blue">this</span>.msi); </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Update
this View of the MultiScaleImage is dragging </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">if</span>(mouseIsDragging) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:#2b91af">Point</span> newOrigin
= <span style="color:blue">new</span><span style="color:#2b91af">Point</span>(); </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> newOrigin.X = currentPosition.X
- </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> (((e.GetPosition(msi).X - dragOffset.X)/msi.ActualWidth)*msi.ViewportWidth); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> newOrigin.Y = currentPosition.Y
- </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> (((e.GetPosition(msi).Y - dragOffset.Y)/msi.ActualWidth)*msi.ViewportWidth); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> msi.ViewportOrigin = newOrigin; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
In our left mouse button down handler we are already handling the dragging functionality
by initializing the mouseIsDragging variable to false, and setting dargOffset to the
initial point that the mouse was at when dragging was started. In the left mouse button
up handler we need to update the dragging indicator that was set to true in the left
mouse button down indicated. The new handler appears below: 
</p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handles
Left Mouse button up event </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> LeftMouseButtonUpHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Change
flag to mouse button no longer pressed </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseButtonPressed = <span style="color:blue">false</span>; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//If
the user wasn't dragging then we do zooming </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">if</span>(!mouseIsDragging) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Check
if shift was pressed. If so we zoom out, otherwise we zoom in </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">bool</span> shiftDown
= (<span style="color:#2b91af">Keyboard</span>.Modifiers &amp; <span style="color:#2b91af">ModifierKeys</span>.Shift)
== <span style="color:#2b91af">ModifierKeys</span>.Shift; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> ZoomFactor = 2.0; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">if</span> (shiftDown)
ZoomFactor = 0.5; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> Zoom(ZoomFactor, <span style="color:blue">this</span>.lastMousePos); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseIsDragging = <span style="color:blue">false</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
We now need to add one more handler. If the mouse goes outside the MultiScaleImage
we what to stop the panning so we need to add a Mouse Leave event handler. In the
handler I am also going to reset the mouse down variable when the user leaves the
MultiScaleImage. This way if they leave the image, lift up the mouse button, and re-enter
the image, it won't continue to pan. 
</p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handles
the mouse leave event </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> MouseLeaveHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseIsDragging = <span style="color:blue">false</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> mouseButtonPressed = <span style="color:blue">false</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
We now need to assign the event, so in the constructor where we wired up the other
events we need to also wire up the MouseLeave event of the MultiScaleImage: 
</p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">public</span> Page() </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> InitializeComponent(); </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Wire
up events </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeftButtonDown
+= LeftMouseButtonDownHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeftButtonUp
+= LeftMouseButtonUpHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseMove
+= MouseMoveHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeave
+= MouseLeaveHandler; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
There you go. Adding panning was that easy. Now if you fire up the site you can click
and dragging the image around and still zoom in and out using click and shit click. 
</p>
        <p>
The next thing we need to do is add zooming with the scroll wheel. We are going to
do this by using the MouseWheelHelper class provided by <a href="http://blois.us/blog/2008/03/ive-heard-number-of-people-wondering.html">Peter
Blois</a>. So grab this class and add it to your Silverlight Application. With Silverlight
2.0 the silverlight application can reach into the DOM using the Sliverlight DOM bridge
and listen to events in the class, abstracting that away from us. 
</p>
        <p>
The first thing we need to do is create an event to handle the mouse wheel. Inside
this event we set the event to handled so that the system knows that the event has
be taken care of, we set the zoom factor by checking the Delta value that is passed
to us from the MouseWheelHelper class. Finally we call the Zoom method passing the
factor that we want to zoom by and the point we are zooming at, just like if the user
had clicked the mouse button to zoom. 
</p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green"> Handles
the mouse wheel events </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;/summary&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="sender"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:gray">///</span>
            <span style="color:green">
            </span>
            <span style="color:gray">&lt;param
name="e"&gt;&lt;/param&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">private</span>
            <span style="color:blue">void</span> MouseWheelHandler(<span style="color:blue">object</span> sender, <span style="color:#2b91af">MouseWheelEventArgs</span> e) </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Notify
that we handled the event </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> e.Handled = <span style="color:blue">true</span>; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> ZoomFactor = e.Delta &gt; 0
? 1.2 : .80; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> Zoom(ZoomFactor, <span style="color:blue">this</span>.lastMousePos); </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
Lastly we wire up with event in our constructor just below where we we wiring up the
rest of the events. The newly modify constructor appears as follows: 
</p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">public</span> Page() </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> InitializeComponent(); </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:green">//Wire
up events </span>
          </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeftButtonDown
+= LeftMouseButtonDownHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeftButtonUp
+= LeftMouseButtonUpHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseMove
+= MouseMoveHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">this</span>.msi.MouseLeave
+= MouseLeaveHandler; </span>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt">
            <span style="color:blue">new</span>
            <span style="color:#2b91af">MouseWheelHelper</span>(<span style="color:blue">this</span>).Moved
+= MouseWheelHandler; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Courier New; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
If you now build and run the application you'll see that the ability to have zoom
with the scroll wheel of the mouse is now present. Hopefully this has demonstrated
that working with the Deep Zoom functionality and Deem Zoom Composer is fairly simple
and can greatly enhance the user experience for a web site. The even better news is
that Deep Zoom composer will now generate all this functionality for you wrapped into
a Silverlight 2.0 application when you export your Deep Zoom image. This particular
sample was pieced together from what I learned from <a href="http://blog.kirupa.com/">Kirupa
Chinnathambi blog</a> who is currently a member of the Expression Blend team at Microsoft. 
</p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <img width="0" height="0" src="http://weblog.ctrlalt313373.com/aggbug.ashx?id=2da2f1cf-b0be-487d-b5b4-4df5aa379407" />
      </body>
      <title>Deep Zoom Example</title>
      <guid isPermaLink="false">http://weblog.ctrlalt313373.com/PermaLink,guid,2da2f1cf-b0be-487d-b5b4-4df5aa379407.aspx</guid>
      <link>http://weblog.ctrlalt313373.com/2008/12/07/DeepZoomExample.aspx</link>
      <pubDate>Sun, 07 Dec 2008 17:21:38 GMT</pubDate>
      <description>&lt;p&gt;
With the release of Silverlight 2.0 also came the functionality of Deep Zoom. Deep
Zoom optimizes the viewing of large images in a smooth manner by partitioning an image
into tiles and levels of resolution of the original image. Using this method allows
for the browser to download a lower resolution image for a faster download speed and
then only grab the higher resolution image if the user zooms in. When the user does
zoom in the tile that represents that section of the higher resolution image is download
to the browser again saving the viewer download time and enhancing the user experience. 
&lt;/p&gt;
&lt;p&gt;
In order to begin working with Deep Zoom the first thing we need to do is prepare
an image for Deep Zoom by creating tiles out of the image of different resolutions.
This would be a bit cumbersome to do by hand so luckily Microsoft has provided us
with the Deep Zoom Composer which you can &lt;a href="http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;ct=res&amp;amp;cd=1&amp;amp;url=http%3A%2F%2Fwww.microsoft.com%2Fdownloads%2Fdetails.aspx%3Ffamilyid%3D457b17b7-52bf-4bda-87a3-fa8a4673f8bf&amp;amp;ei=igM8SbX_MojaM8-R2a8F&amp;amp;usg=AFQjCNE5i8Ndl2AZGRxmQ8seQB1MZawSVA&amp;amp;sig2=3w05HjQyqEhCJaSEFkrewA"&gt;download&lt;/a&gt; for
free. This allows us to create the Deep Zoom images and even allows us to create a
collage of image in Deep Zoom. We will be doing the latter, using the numerous amount
of photos that I took while traveling through Europe for the month of September. 
&lt;/p&gt;
&lt;p&gt;
The first thing we need to do is create a new project in Deep Zoom Composer. Do this
by running the Deep Zoom Composer and selecting new project. After doing this you
will see three tabs along the top – Import, Compose, and Export. If you are not already
on the Import tab, select it, and then we need to add the images that we want to work
with. In my case I will be adding in all my pictures from Rome. Click the Add Image…
button on the right and select the images that you want to add. Remember that you
can select multiple images at once to get your images imported in faster. 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa1.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Once the images are imported we then switch over to the Compose tab. The tab allows
you to create how the final image will look in your Silverlight Application. Select
your imported images from the side and place them on the canvas how you would like
them to appear. You can zoom in and out on the canvas and place your photos at different
depths, even embedding them within each other. For instance I have an image of the
Coliseum from the distance with a sign that is on the side of it. I then have a closer
image of that sign as another picture. The Deep Zoom composer allows me to embed the
more detailed image of the sign into the image of the Coliseum. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa2.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa3.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
In the composer you also have the ability to associate tags with the images. I have
associated various tags with all my images. Through the composer you can only apply
one string as a tag, so I have used this field to enter multiple "tags" separated
by commas. In a future tutorial I will demonstrate how to create a tag filter to filter
down images shown in the MultiScaleImage. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa4.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Once we have exported the images from Deep Zoom Composer it is now time to get our
hands dirty in Visual Studio 2008. In order to work with Silverlight 2.0 applications
you are going to need 3 things, Visual Studio 2008 SP1, the Silverlight SDK, and the
Silverlight tools for Visual Studio 2008. Fire up vs2008, go to File-&amp;gt;New-&amp;gt;Project
and under Visual C# (or if you prefer you can select VB) select Silverlight. Then
select Silverlight Application on the right, name your solution, and select where
you want to save it. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa5.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Next a window will appear that will ask you if you want to add a new ASP.NET web project
to the solution or generate a test page at build time. Every Silverlight application
needs to be hosted inside a web application so we will let Visual Studio add a project
to our solution for this purpose. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa6.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
If you now look in the Solution Explorer you will see that we have an empty Silverlight
Application called DeepZoomExample2 and a ASP.NET web project called DeepZoomExample2.Web.
The web project has two pages that were created for us, an aspx page and a html page
that hosts our Silverlight Application. 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa7.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Next we need to add our exported images to the web project. Add a new folder under
the ClientBin folder on the Web Project and call it GeneratedImages. The ClientBin
folder is where the compiled .xap file from your Silverlight will live so this is
the easiest place to put our exported files. Now go into your exported folder from
the Deep Zoom Composer and open up the generated images folder and copy the dzc_output_files
folder, and the dzc_output_images folder along with the three files, dzc_output.xml,
Metadata.xml, SparseImageSceneGraph.xml into the new GeneratedImages folder that you
created in your web project. If you used a lot of images this may take some time to
copy. Your Solution Explorer should now look like the following image. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa8.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Now it's time to start writing some code. First we add a MultiScaleImage to the Page.xaml
file. The Source property will be directed at the dzc_output.zml files that we copied
into our GeneratedImages folder. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;Grid&lt;/span&gt;&lt;span style="color:blue"&gt; &lt;/span&gt;&lt;span style="color:red"&gt;x:Name&lt;/span&gt;&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;LayoutRoot&lt;/span&gt;"&lt;span style="color:blue"&gt; &lt;/span&gt;&lt;span style="color:red"&gt;Background&lt;/span&gt;&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;White&lt;/span&gt;"&lt;span style="color:blue"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;MultiScaleImage&lt;/span&gt;&lt;span style="color:blue"&gt; &lt;/span&gt;&lt;span style="color:red"&gt;x:Name&lt;/span&gt;&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;msi&lt;/span&gt;"&lt;span style="color:blue"&gt; &lt;/span&gt;&lt;span style="color:red"&gt;ViewportWidth&lt;/span&gt;&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;1.0&lt;/span&gt;"&lt;span style="color:blue"&gt; &lt;/span&gt;&lt;span style="color:red"&gt;Source&lt;/span&gt;&lt;span style="color:blue"&gt;=&lt;/span&gt;"&lt;span style="color:blue"&gt;/GeneratedImages/dzc_output.xml&lt;/span&gt;"&lt;span style="color:blue"&gt; /&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;Grid&lt;/span&gt;&lt;span style="color:blue"&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
This is all we need to do to get the basic images on the screen, but that isn't very
exciting so lets wire up some zooming using the mouse button. In the Page.xaml.cs
file we need to add a few variables to store some information: 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color:green; font-family:Courier New; font-size:10pt"&gt;//This variable
is used to know if the user has just click the left button or has clicked and dragged &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;bool&lt;/span&gt; mouseIsDragging
= &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Indicates
if left mouse button is down &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;bool&lt;/span&gt; mouseButtonPressed
= &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Starting
Point of the Drag &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt; dragOffset; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Get
Current ViewPort position of MSI &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt; currentPosition; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Last
Position of Mouse &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt; lastMousePos
= &lt;span style="color:blue"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt;(); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;public&lt;/span&gt; &lt;span style="color:blue"&gt;double&lt;/span&gt; ZoomFactor &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;get&lt;/span&gt;; &lt;span style="color:blue"&gt;set&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We then have three mouse events that we need to handle, LeftMouseButton down, LeftMouseButton
up, and Mouse Move. Then we need to handle the actual zoom. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handles
Left Mouse button down event &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; LeftMouseButtonDownHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Indicate
that the button is down &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseButtonPressed = &lt;span style="color:blue"&gt;true&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Reset
Dragging &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseIsDragging = &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Set
Starting point of the drag if the user start dragging &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; dragOffset = e.GetPosition(&lt;span style="color:blue"&gt;this&lt;/span&gt;); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; currentPosition = msi.ViewportOrigin; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
In the left mouse button down even, we first set the indicator that the button is
pressed. We then reset the dragging indicator, get the current position of the mouse,
and finally get the current position of the MultiScaleImage. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handles
Left Mouse button up event &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; LeftMouseButtonUpHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Change
flag to mouse button no longer pressed &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseButtonPressed = &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//If
the user wasn't dragging then we do zooming &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;if&lt;/span&gt;(!mouseIsDragging) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Check
if shift was pressed. If so we zoom out, otherwise we zoom in &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;bool&lt;/span&gt; shiftDown
= (&lt;span style="color:#2b91af"&gt;Keyboard&lt;/span&gt;.Modifiers &amp;amp; &lt;span style="color:#2b91af"&gt;ModifierKeys&lt;/span&gt;.Shift)
== &lt;span style="color:#2b91af"&gt;ModifierKeys&lt;/span&gt;.Shift; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; ZoomFactor = 2.0; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;if&lt;/span&gt; (shiftDown)
ZoomFactor = 0.5; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; Zoom(ZoomFactor, &lt;span style="color:blue"&gt;this&lt;/span&gt;.lastMousePos); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
When the left mouse button is lifted we change the flag that indicates that the left
mouse button is down and if the user was not dragging. We then check to see if shift
was pressed. If shift was not pressed we zoom in by a factor of 2, but if shift was
pressed we zoom out by a factor of .5. We then call our zoom function (which we have
yet to create) with the zoom factor and the last point the mouse was at. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p style="margin-left: 36pt"&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:gray"&gt; ///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handlers
the moving of the mouse &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; MouseMoveHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.lastMousePos
= e.GetPosition(&lt;span style="color:blue"&gt;this&lt;/span&gt;.msi); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
With the mouse move function all we need to do is capture the position that the mouse
is at. Finally in the below Zoom function that is called from the LeftMouseButtonUpHandler,
we do the actual zooming. 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; Zoom(&lt;span style="color:blue"&gt;double&lt;/span&gt; zoom, &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt; pointToZoom) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt; logicalPoint
= &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.ElementToLogicalPoint(pointToZoom); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.ZoomAboutLogicalPoint(zoom,
logicalPoint.X, logicalPoint.Y); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
As you can see above we have to translate the mouse pointer relative to our MultiScaleImage
and then we use the ZoomAboutLogicalPoint method to handle the zooming for us. The
last thing we need to do is wire up the events to the MultiScaleImage control in the
Page constructor which will look like the following: 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt; Page() &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; InitializeComponent(); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Wire
up events &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeftButtonDown
+= LeftMouseButtonDownHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeftButtonUp
+= LeftMouseButtonUpHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseMove
+= MouseMoveHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
If you now run the application you will get the layout of all images on your screen
as seen in the first picture below, and if I click on the picture of St. Peter's Square
in the center of the image the MultiScaleImage control will zoom in on that particular
image as seen in the second picture below. Holding down the shift key while clicking
will zoom the MultiScaleImage back out. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa9.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://weblog.ctrlalt313373.com/content/binary/120708_1721_DeepZoomExa10.png" alt="" /&gt; 
&lt;/p&gt;
&lt;p&gt;
In order to enable panning we need to augment a few functions that we have already
created. Obviously we need to modify the MouseMoveHandler. Initially all this event
was doing was updating the mouse position so that when we zoomed in or out we knew
where the mouse was pointing. Now we are going to have it check to see if the mouse
button is down to indicate that dragging is occurring. Also if the mouse is dragging
we need to update the position so that the MultiScaleImage is centered on to where
the mouse is dragging. Our new MouseMoveHandler appears below. 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handlers
the moving of the mouse &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; MouseMoveHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;if&lt;/span&gt;(mouseButtonPressed) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseIsDragging = &lt;span style="color:blue"&gt;true&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.lastMousePos
= e.GetPosition(&lt;span style="color:blue"&gt;this&lt;/span&gt;.msi); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Update
this View of the MultiScaleImage is dragging &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;if&lt;/span&gt;(mouseIsDragging) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt; newOrigin
= &lt;span style="color:blue"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Point&lt;/span&gt;(); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; newOrigin.X = currentPosition.X
- &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; (((e.GetPosition(msi).X - dragOffset.X)/msi.ActualWidth)*msi.ViewportWidth); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; newOrigin.Y = currentPosition.Y
- &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; (((e.GetPosition(msi).Y - dragOffset.Y)/msi.ActualWidth)*msi.ViewportWidth); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; msi.ViewportOrigin = newOrigin; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
In our left mouse button down handler we are already handling the dragging functionality
by initializing the mouseIsDragging variable to false, and setting dargOffset to the
initial point that the mouse was at when dragging was started. In the left mouse button
up handler we need to update the dragging indicator that was set to true in the left
mouse button down indicated. The new handler appears below: 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handles
Left Mouse button up event &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; LeftMouseButtonUpHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Change
flag to mouse button no longer pressed &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseButtonPressed = &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//If
the user wasn't dragging then we do zooming &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;if&lt;/span&gt;(!mouseIsDragging) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Check
if shift was pressed. If so we zoom out, otherwise we zoom in &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;bool&lt;/span&gt; shiftDown
= (&lt;span style="color:#2b91af"&gt;Keyboard&lt;/span&gt;.Modifiers &amp;amp; &lt;span style="color:#2b91af"&gt;ModifierKeys&lt;/span&gt;.Shift)
== &lt;span style="color:#2b91af"&gt;ModifierKeys&lt;/span&gt;.Shift; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; ZoomFactor = 2.0; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;if&lt;/span&gt; (shiftDown)
ZoomFactor = 0.5; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; Zoom(ZoomFactor, &lt;span style="color:blue"&gt;this&lt;/span&gt;.lastMousePos); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseIsDragging = &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We now need to add one more handler. If the mouse goes outside the MultiScaleImage
we what to stop the panning so we need to add a Mouse Leave event handler. In the
handler I am also going to reset the mouse down variable when the user leaves the
MultiScaleImage. This way if they leave the image, lift up the mouse button, and re-enter
the image, it won't continue to pan. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handles
the mouse leave event &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; MouseLeaveHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseIsDragging = &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; mouseButtonPressed = &lt;span style="color:blue"&gt;false&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We now need to assign the event, so in the constructor where we wired up the other
events we need to also wire up the MouseLeave event of the MultiScaleImage: 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt; Page() &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; InitializeComponent(); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Wire
up events &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeftButtonDown
+= LeftMouseButtonDownHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeftButtonUp
+= LeftMouseButtonUpHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseMove
+= MouseMoveHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeave
+= MouseLeaveHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
There you go. Adding panning was that easy. Now if you fire up the site you can click
and dragging the image around and still zoom in and out using click and shit click. 
&lt;/p&gt;
&lt;p&gt;
The next thing we need to do is add zooming with the scroll wheel. We are going to
do this by using the MouseWheelHelper class provided by &lt;a href="http://blois.us/blog/2008/03/ive-heard-number-of-people-wondering.html"&gt;Peter
Blois&lt;/a&gt;. So grab this class and add it to your Silverlight Application. With Silverlight
2.0 the silverlight application can reach into the DOM using the Sliverlight DOM bridge
and listen to events in the class, abstracting that away from us. 
&lt;/p&gt;
&lt;p&gt;
The first thing we need to do is create an event to handle the mouse wheel. Inside
this event we set the event to handled so that the system knows that the event has
be taken care of, we set the zoom factor by checking the Delta value that is passed
to us from the MouseWheelHelper class. Finally we call the Zoom method passing the
factor that we want to zoom by and the point we are zooming at, just like if the user
had clicked the mouse button to zoom. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; Handles
the mouse wheel events &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;/summary&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="sender"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:gray"&gt;///&lt;/span&gt;&lt;span style="color:green"&gt; &lt;/span&gt;&lt;span style="color:gray"&gt;&amp;lt;param
name="e"&amp;gt;&amp;lt;/param&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;private&lt;/span&gt; &lt;span style="color:blue"&gt;void&lt;/span&gt; MouseWheelHandler(&lt;span style="color:blue"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;MouseWheelEventArgs&lt;/span&gt; e) &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Notify
that we handled the event &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; e.Handled = &lt;span style="color:blue"&gt;true&lt;/span&gt;; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; ZoomFactor = e.Delta &amp;gt; 0
? 1.2 : .80; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; Zoom(ZoomFactor, &lt;span style="color:blue"&gt;this&lt;/span&gt;.lastMousePos); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Lastly we wire up with event in our constructor just below where we we wiring up the
rest of the events. The newly modify constructor appears as follows: 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;public&lt;/span&gt; Page() &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; { &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; InitializeComponent(); &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:green"&gt;//Wire
up events &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeftButtonDown
+= LeftMouseButtonDownHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeftButtonUp
+= LeftMouseButtonUpHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseMove
+= MouseMoveHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;this&lt;/span&gt;.msi.MouseLeave
+= MouseLeaveHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; &lt;span style="color:blue"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MouseWheelHelper&lt;/span&gt;(&lt;span style="color:blue"&gt;this&lt;/span&gt;).Moved
+= MouseWheelHandler; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-family:Courier New; font-size:10pt"&gt; } &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
If you now build and run the application you'll see that the ability to have zoom
with the scroll wheel of the mouse is now present. Hopefully this has demonstrated
that working with the Deep Zoom functionality and Deem Zoom Composer is fairly simple
and can greatly enhance the user experience for a web site. The even better news is
that Deep Zoom composer will now generate all this functionality for you wrapped into
a Silverlight 2.0 application when you export your Deep Zoom image. This particular
sample was pieced together from what I learned from &lt;a href="http://blog.kirupa.com/"&gt;Kirupa
Chinnathambi blog&lt;/a&gt; who is currently a member of the Expression Blend team at Microsoft. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://weblog.ctrlalt313373.com/aggbug.ashx?id=2da2f1cf-b0be-487d-b5b4-4df5aa379407" /&gt;</description>
      <comments>http://weblog.ctrlalt313373.com/CommentView,guid,2da2f1cf-b0be-487d-b5b4-4df5aa379407.aspx</comments>
      <category>Deep Zoom</category>
      <category>Deep Zoom Composer</category>
      <category>Development</category>
      <category>Silverlight</category>
    </item>
  </channel>
</rss>