Click here to Skip to main content
15,884,298 members
Articles / Silverlight

Silverlight 4: Mouse Wheel Support in your Application

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
6 Dec 2009CPOL1 min read 13.8K   2  
Silverlight 4 now has support for Mouse Wheel. From now onwards, you can use mouse wheel event to trigger on mouse wheel rotation. Until the release of Silverlight 4 Beta 1 you had to write JavaScript code & a huge lines of code in C#. Now just forget about those lines. Your code will be clean.

Silverlight 4 now has support for Mouse Wheel. From now onwards, you can use mouse wheel event to trigger on mouse wheel rotation. Until the release of Silverlight 4 Beta 1, you had to write JavaScript code & huge lines of code in C#. Now just forget about those lines. Your code will be clean.

If you want to use the clean coding for mouse wheel, you have to just register & implement the said event in your code. Apart from the MouseLeftButtonDown / MouseLeftButtonUp / MouseRightButtonDown / MouseRightButtonUp / MouseEnter / MouseLeave events there you will find another event called MouseWheel. This event is responsible for cleaning up your code to implement the feature. You can also override the OnMouseWheel event in your main control.

See the below code:

C#
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
    base.OnMouseWheel(e);

    txbMouseWheelValue.Text = string.Format("Mouse Wheel Value: {0}", e.Delta);

    if (e.Delta > 0)
        rotateBrdWheeler.Angle += 10;
    else
        rotateBrdWheeler.Angle -= 10;
}

Here when the mouse wheel event is registered, it will set e.Delta as the output of mouse wheel rotation. You can check whether the value is positive / negative & depending on that, you can decide your own logic. In the demo app, I am rotating a Rectangle by 10 degrees depending on the sign of delta. You can do your own logic there.

It’s so easy. So, go ahead & clean your code (only supports in Silverlight 4). Enjoy the new feature. Cheers…  :)

This article was originally posted at http://kunal2383.blogspot.com/feeds/posts/default

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India

Kunal Chowdhury is a former Microsoft "Windows Platform Development" MVP (Most Valuable Professional, 2010 - 2018), a Codeproject Mentor, Speaker in various Microsoft events, Author, passionate Blogger and a Senior Technical Lead by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows app development. He posts his findings, articles, tutorials in his technical blog (www.kunal-chowdhury.com) and CodeProject.


Books authored:


Connect with Kunal on:





Comments and Discussions

 
-- There are no messages in this forum --