Silver Light 4.0 feature # Mouse wheel event


In this article, I am going to give a basic introduction of Mouse wheel event in Silver Light 4.0.


Silver Light 4.0 has been introduced Mouse wheel event. Now on mouse wheel event can be captured. And the event can be raised for any silver light control.


In below image you can see, MouseWheel event has been included.



If you see the description above it is saying

“This event occurs, when user rotates the mouse wheel while pointer is over a UI Elements ”


I have an image on my silver light page.

<UserControl x:Class=”MouseWheelevent.MainPage”






d:DesignHeight=”300″ d:DesignWidth=”400″>

<Grid x:Name=”LayoutRoot” Background=”Azure” Height=”auto” Width=”auto”>

<Image x:Name=”MyImage” Width=”300″ Height=”400″ Source=”a.jpg” />



Output of above

Now we are going to resize the image on mouse wheel event.

 Adding Mouse Wheel event with image


MyImage.MouseWheel += newMouseWheelEventHandler(mymousewheelevent);

Handling the event

void mymousewheelevent(object sender, MouseWheelEventArgs e)
double height = MyImage.Height;double width = MyImage.Width;
int delta = e.Delta;
height += delta;
width += delta / 2;
MyImage.Height = height > 650 ? 400 : height;
MyImage.Width = width > 600 ? 300 : width;



  1. Just saving current height and width in variables.
  2. Using Delta method on event args , change could be captured.
  3. Then just setting the dimension of image with some logic.


Click on image and scroll the mouse ball. Image size will be change.

 So, we can attach the Mouse wheel event with any control.


In this article, I gave basic introduction of MouseWheel event in Silver Light 4.0. Thanks for reading.



Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

One thought on “Silver Light 4.0 feature # Mouse wheel event”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s