Mouse Wheel Behavior for Silverlight 3

As you may know, Silverlight 2 did not support the mouse wheel natively. You needed to hook into the HTML bridge and access the mouse wheel events from the DOM, hit test the control that it intersected, then act on the mouse wheel data. Silverlight 3 still does not implement the mouse wheel for scrolling by default, but it does expose a MouseWheel event on UIElement that eliminates the need to hook the events in the DOM.

One caveat though is that the MouseWheel event only fires under Internet Explorer or out-of-browser applications. For other browsers and operating systems, you will still need to use the DOM’s mouse wheel events.

So anyway, I wrapped up the mouse wheel code in a “MouseWheelBehavior” that you can just drop onto any element that contains a ScrollViewer element (multi-line textbox, list box, etc.) and it implements vertical scrolling with no code.

MouseWheelBehavior.cs