Zoom-In and Zoom-Out An Image with Mouse Wheel in Silverlight 4


Introduction

In this article we will see how we can zoom in or zoom out an image with mouse wheel scroll in Silverlight 4.

Creating Silverlight Application

Fire up Visual Studio 2010 and create a Silverlight Application, name the solution as MouseWheelSample.

ZoomInOut1.gif


Let's add an Image control.

ZoomInOut2.gif

ZoomInOut3.gif

In Silverlight 4 we have a new event handler and that is called MouseWheel. So let's subscribe the event for the image.

ZoomInOut4.gif

Now that we have subscribed the event. As you see in the above code display we have the Property called Delata which will be added to the width and height respectively to give the new values and then we are assigning the value.

We are also checking the minimum width and height values.

Let's run the application and click on the image first other wise the focus is not set.

ZoomInOut5.gif

The above image displays the default state when Mouse wheel is not triggered.

Now let's scroll the mouse.

ZoomInOut6.gif

And we have the zoom in effect for the image when we mouse scroll.

That's it.

Hope this article helps.
 

Up Next
    Ebook Download
    View all
    Learn
    View all