Silver Light 4.0 feature - Mouse wheel event

No.of Views640
Bookmarked0 times
Downloads 
Votes0
By  Dhananjay Kumar   On  16 Feb 2010 00:02:57
Tag : Silver Light and XAML , Miscellaneous
Silver Light 4.0 feature No-02 Mouse wheel event
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Objective

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

Introduction

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.

Image Loading

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 “

Sample
I have an image on my silver light page.

<UserControl x:Class="MouseWheelevent.MainPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"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" /></Grid></UserControl>

Output of above

Image Loading

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

Adding Mouse Wheel event with image

MyImage.MouseWheel += new MouseWheelEventHandler(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; 
        }

Explanation
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.

Output

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

Image Loading

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

Conclusion

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

 

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top