More on the mouse wheel

Daniel left a comment on my post about mouse wheel support saying he'd managed to get it working in managed code so I decided to take another look. It turns out that the object to which you attach your handler is critical and differs between IE and Firefox:

    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); // IE
    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); //FF

So you need to attach to the onmousewheel event on the Document object for IE and the DOMMouseScroll event on the Window object for FireFox (I haven't tried Safari I'm afraid). That said, this didn't get me very much further as I can't recover the scroll wheel data for Firefox. My MouseScrollWheel handler looks like this:

 private void MouseScrollWheel(object sender, HtmlEventArgs e)
    ScriptObject eventobject = e.EventObject;

    double wheelAmount =
        eventobject.GetProperty("detail") != null ?
        (double)eventobject.GetProperty("detail") * -1.0 :
        (double)eventobject.GetProperty("wheelDelta") / 40.0;

    if (wheelAmount > 0)


as IE uses the events wheelDelta property and Firefox uses the detail property (there is also a difference in scaling between the two hence the twiddle factors). There's a good tutorial on the scroll wheel here. The trouble is, the detail property is always 0.0 for me so this solution works in IE but not in Firefox (well it works in Firefox but the image zooms out irrespective of which way you turn the scroll wheel!). Ideas anyone?

Technorati Tags: silverlight,ie,firefox