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:
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… :)
CodeProject